flat assembler
Message board for the users of flat assembler.
Index
> Linux > creating shared libraries - how to do make PIC with GOT Goto page Previous 1, 2 |
Author |
|
LocoDelAssembly 26 Sep 2006, 02:44
Seems that I'll never get it work, 4 hours trying, 4 hours!!!
Even using "-rpath /home/oem/Desktop/test/" doesn't work, throws "bash: ./shared-lib-test: No such file or directory ". My last attempt was this: Quote: root@athlon64:/home/oem/Desktop/test# ld -m elf_i386 -shared -o shared-lib.so shared-lib.o But I'm still geting the "bash: ./shared-lib-test: No such file or directory" message (but the file exists of course). Here the readelf -a shared-lib-test [edit] <Removed to improve screen space>[/edit] PS: Note that if I link statically I can execute shared-lib-test without problems (linking against shared-lib.o instead of shared-lib.so), but it's not shared in that case... [edit] Here the definitive sequence to get it work on Ubuntu 64-bit Dapper Drake (6.06.1 LTS) Quote: fasm shared-lib.asm Note that this is for testing, you have to follow a diferent procedure in order to install the shared library (check the link that Tomasz posted below). Regards [/edit] Last edited by LocoDelAssembly on 26 Sep 2006, 16:04; edited 1 time in total |
|||
26 Sep 2006, 02:44 |
|
Tomasz Grysztar 26 Sep 2006, 07:33
The way you linked it, to execute the program correctly you have to run it like:
Code: /lib/ld-linux.so.2 --library-path . shared-lib-test Or better, link the test program like this: Code: ld -dynamic-linker /lib/ld-linux.so.2 -o shared-lib-test shared-lib-test.o shared-lib.so and then execute with command: Code: LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH ./shared-lib-test PS. See http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html for some info. |
|||
26 Sep 2006, 07:33 |
|
LocoDelAssembly 26 Sep 2006, 16:15
Quote: PS. See http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html for some info. I read it yesterday but seems that I got it wrong... Using "ld -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o shared-lib-test shared-lib-test.o shared-lib.so" shared-lib-test works using /lib/shared-lib.so or /lib32/shared-lib.so and using "ld -m elf_i386 -rpath . -dynamic-linker /lib/ld-linux.so.2 -o shared-lib-test shared-lib-test.o shared-lib.so" works with ./shared-lib.so . No need to use LD_LIBRARY_PATH in both cases Thank you a lot!! PS: I edited my previous posts [edit] Tested in the 32-bit version, works too [/edit] |
|||
26 Sep 2006, 16:15 |
|
Tomasz Grysztar 26 Sep 2006, 18:49
Strange news: I don't know how it was actually working, but I discovered that there was a bug that caused the generated code to be not really PIC. [Maybe ld can make shared library even from non-PIC code, by choosing some random fixed base address for it? That needs investigating.]
I fixed the bug and added the PLT operator at the same time. You use it just like: Code: call PLT printf to call the external procedure via PLT. You can also do something like: Code: extrn 'printf' as _printf printf = PLT _printf and be able the to simply call the "printf" label, while assembler will make this call work through the Procedure Linkage Table. Well, it appears I have to rewrite the first post with more information how to get this all working. A new thread perhaps? |
|||
26 Sep 2006, 18:49 |
|
LocoDelAssembly 26 Sep 2006, 19:29
aaahh, I forgot to tell something more, using "objdump -D shared-lib-test" I saw that it resolves using the same technique that MASM uses when you call an API (calling a jmp). However the jmp is not a "jmp dword ptr" like MASM but a "jmp rel32".
Do you mean that or I'm still getting it wrong? [edit] I just found this http://www.iecc.com/linker/linker10.html . Nice explanation [/edit] |
|||
26 Sep 2006, 19:29 |
|
Tomasz Grysztar 26 Sep 2006, 20:38
No, it was about relocations in shared-lib.o, not shared-lib-test (and the latter is created by ld and not fasm, anyway).
|
|||
26 Sep 2006, 20:38 |
|
FlashBurn 27 Sep 2006, 06:21
Thanks, I now will have a deeper look into the elf specifications and will see if I will get shared library support for my os working!
|
|||
27 Sep 2006, 06:21 |
|
pelaillo 29 Sep 2006, 22:50
Quote:
Now I understand why a PIC version of my example (posted here) wasn't working. I arrived nowhere and then move the focus away. Maybe is time to fix it. |
|||
29 Sep 2006, 22:50 |
|
LocoDelAssembly 07 Aug 2008, 00:26
Tomasz Grysztar wrote: Well, it appears I have to rewrite the first post with more information how to get this all working. A new thread perhaps? Could you? Because: Code: format ELF section '.text' executable public main extrn printf main: push msg call PLT printf add esp, 4 ret msg db "Hello World", 0xA,0 ;---- ;flat assembler version 1.67.28 (16384 kilobytes memory) ;libcdemo.asm [10]: ; call PLT printf ;error: invalid use of symbol. PS: Note the incorrect version number 1.67.28 |
|||
07 Aug 2008, 00:26 |
|
Tomasz Grysztar 11 Nov 2008, 13:50
It's going to be fixed finally in 1.67.29.
|
|||
11 Nov 2008, 13:50 |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.