flat assembler
Message board for the users of flat assembler.
Index
> Linux > PIE (position independent executable) Goto page Previous 1, 2 |
Author |
|
sleepsleep 03 Jul 2013, 09:22
hi Endre,
thanks for the confirmation, am still struggle with this issue, it is still unsolved in my environment, i will attempt to buildroot, still finding how to do this stuff, |
|||
03 Jul 2013, 09:22 |
|
Turbo Lover 03 Jul 2013, 09:31
why is it DYN?
|
|||
03 Jul 2013, 09:31 |
|
sleepsleep 03 Jul 2013, 09:43
no idea too, maybe i need to study linux executable format, "(
|
|||
03 Jul 2013, 09:43 |
|
Endre 03 Jul 2013, 14:45
What if you link it statically (e.g. with compiler switch -static)?
|
|||
03 Jul 2013, 14:45 |
|
sleepsleep 03 Jul 2013, 16:54
Endre wrote: What if you link it statically (e.g. with compiler switch -static)? hi Endre, static link working! i use gcc -static fasmoutput.o -o executablename as suggested by you, this is great! |
|||
03 Jul 2013, 16:54 |
|
Bob++ 03 Jul 2013, 17:55
I'm not familiar with this linux stuff, but what error do you get?
|
|||
03 Jul 2013, 17:55 |
|
sleepsleep 03 Jul 2013, 17:58
Bob++ wrote: I'm not familiar with this linux stuff, but what error do you get? Can't modify application's text section; use the GCC option -fPIE for position-independent executables. actually i got no idea what error is that, but execution of that executable bring the above error message. -static as suggested works fine, but dynamic load doesnt work. |
|||
03 Jul 2013, 17:58 |
|
Endre 04 Jul 2013, 10:50
Then to counter check whether fasm generates proper elf object compile the following code (I implemented you the ccall macro. The file name is assumed to be a1.S) with "as". That is
gcc -g a1.S -o a1 (-g is for debug info, so you can debug your code with gdb) Code: .altmacro .macro ccall func:req, args:vararg local argc argc = 0 /* recursive reverse pusher */ .macro pusher parg1, pargs:vararg .ifnb \parg1 /* .print "\parg1" */ pusher \pargs push \parg1 argc = argc + 1 .endif .endm pusher \args call \func /* check if there were arguments pushed */ .if \argc add esp, argc * 4 .endif .purgem pusher .endm .intel_syntax noprefix .global main .extern getpid .extern printf .text .align 4 main: ccall getpid ccall printf (offset msg), eax mov eax, 1 /* int 0x80 */ ret msg: .asciz "hello world %d\n" if it works, then something is wrong with fasm on your system. |
|||
04 Jul 2013, 10:50 |
|
sleepsleep 04 Jul 2013, 19:57
it doesnt works,
same error after i did gcc -g a1.S -o a1 Can't modify application's text section; use the GCC option -fPIE for position-independent executables. |
|||
04 Jul 2013, 19:57 |
|
Endre 05 Jul 2013, 08:05
Then this must be a feature of alpine linux. I have one more idea, but I doubt it works: try to apply compiler switch -muclibc. I don't know too much about uClibc, but as I remember one has to use a special linker for linking on it. Probably this linker (ld-uclibc or what) has been installed on your system. So my experiment would test whether the compiler chooses the right linker if you add the compiler switch above. You may want to use the switch -v to get more info from the compiler. As a counter-test there is another switch named -mglibc which you can also attempt to use just to check if linking against glibc works.
|
|||
05 Jul 2013, 08:05 |
|
gens 05 Jul 2013, 12:57
sleep stated the output of ldd
checking sub-depends for '/lib/libc.so.0.9.32' checking sub-depends for '/lib/ld-uClibc.so.0.9.32' im guessing its a problem with uclibc or gcc having problems with uclibc did you try some C programs ? how about some other calls like write() ? position independent whatever is when you are making a library, they should not be needed to call a library maybe its just passing a wrong pointer, 32bit calls return to the stack try setting up the stack, maybe the stack pointers are messed up http://en.wikipedia.org/wiki/X86_calling_conventions#Caller_clean-up bdw you can use latrace, strace and gdb to find out whats wrong and if all else fails you can make it in C then decompile it |
|||
05 Jul 2013, 12:57 |
|
sleepsleep 05 Jul 2013, 13:11
gens wrote: sleep stated the output of ldd thanks for tips, i will try to see how to solve this mystery, (am still a linux newbie) |
|||
05 Jul 2013, 13:11 |
|
Endre 05 Jul 2013, 17:00
Have you already tried -muclibc?
|
|||
05 Jul 2013, 17:00 |
|
sleepsleep 05 Jul 2013, 17:27
i tried the following, Endre,
using the code.S as suggested by you to unveil da mysteries, Code: sleepserver:/# gcc -g -v -muclibc a1.S -o a1 Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/lto-wrapper Target: i486-alpine-linux-uclibc Configured with: /home/buildozer/aports/main/gcc/src/gcc-4.7.3/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --build=i486-alpine-linux-uclibc --host=i486-alpine-linux-uclibc --target=i486-alpine-linux-uclibc --with-pkgversion='Alpine 4.7.3' --disable-altivec --disable-build-with-cxx --disable-checking --disable-fixed-point --disable-libssp --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --enable-__cxa_atexit --enable-cld --enable-esp --enable-cloog-backend --enable-languages=c,c++,objc,java,go,fortran --enable-shared --enable-target-optspace --enable-tls --enable-threads --with-dynamic-linker=ld-uClibc.so.0.9.32 --with-dynamic-linker-prefix=/lib --with-system-zlib --without-system-libunwind Thread model: posix gcc version 4.7.3 (Alpine 4.7.3) COLLECT_GCC_OPTIONS='-g' '-v' '-muclibc' '-o' 'a1' '-mtune=i486' '-march=i486' '-fPIE' '-pie' /usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/cc1 -E -lang-asm -quiet -v a1.S -fno-strict-overflow -muclibc -mtune=i486 -march=i486 -fPIE -g -fworking-directory -fstack-protector-all -fno-directives-only -o /tmp/ccT5TnL8.s ignoring nonexistent directory "/usr/local/include" ignoring nonexistent directory "/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/include /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-g' '-v' '-muclibc' '-o' 'a1' '-mtune=i486' '-march=i486' '-fPIE' '-pie' /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/bin/as --gdwarf2 -v --32 -o /tmp/cciRrhP5.o /tmp/ccT5TnL8.s GNU assembler version 2.23.2 (i486-alpine-linux-uclibc) using BFD version (GNU Binutils) 2.23.2 COMPILER_PATH=/usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/:/usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/:/usr/libexec/gcc/i486-alpine-linux-uclibc/:/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/:/usr/lib/gcc/i486-alpine-linux-uclibc/:/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/bin/ LIBRARY_PATH=/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/:/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/lib/:/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-g' '-v' '-muclibc' '-o' 'a1' '-mtune=i486' '-march=i486' '-fPIE' '-pie' /usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-uClibc.so.0.9.32 -pie -z now -o a1 /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../Scrt1.o /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../crti.o /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/crtbeginS.o -L/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3 -L/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/lib -L/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../.. /tmp/cciRrhP5.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/crtendS.o /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../crtn.o Code: sleepserver:/# gcc -g -v -mglibc a1.S -o a1 Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/lto-wrapper Target: i486-alpine-linux-uclibc Configured with: /home/buildozer/aports/main/gcc/src/gcc-4.7.3/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --build=i486-alpine-linux-uclibc --host=i486-alpine-linux-uclibc --target=i486-alpine-linux-uclibc --with-pkgversion='Alpine 4.7.3' --disable-altivec --disable-build-with-cxx --disable-checking --disable-fixed-point --disable-libssp --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --enable-__cxa_atexit --enable-cld --enable-esp --enable-cloog-backend --enable-languages=c,c++,objc,java,go,fortran --enable-shared --enable-target-optspace --enable-tls --enable-threads --with-dynamic-linker=ld-uClibc.so.0.9.32 --with-dynamic-linker-prefix=/lib --with-system-zlib --without-system-libunwind Thread model: posix gcc version 4.7.3 (Alpine 4.7.3) COLLECT_GCC_OPTIONS='-g' '-v' '-mglibc' '-o' 'a1' '-mtune=i486' '-march=i486' '-fPIE' '-pie' /usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/cc1 -E -lang-asm -quiet -v a1.S -fno-strict-overflow -mglibc -mtune=i486 -march=i486 -fPIE -g -fworking-directory -fstack-protector-all -fno-directives-only -o /tmp/ccmN2lyH.s ignoring nonexistent directory "/usr/local/include" ignoring nonexistent directory "/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/include /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-g' '-v' '-mglibc' '-o' 'a1' '-mtune=i486' '-march=i486' '-fPIE' '-pie' /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/bin/as --gdwarf2 -v --32 -o /tmp/cc6f9bmf.o /tmp/ccmN2lyH.s GNU assembler version 2.23.2 (i486-alpine-linux-uclibc) using BFD version (GNU Binutils) 2.23.2 COMPILER_PATH=/usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/:/usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/:/usr/libexec/gcc/i486-alpine-linux-uclibc/:/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/:/usr/lib/gcc/i486-alpine-linux-uclibc/:/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/bin/ LIBRARY_PATH=/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/:/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/lib/:/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-g' '-v' '-mglibc' '-o' 'a1' '-mtune=i486' '-march=i486' '-fPIE' '-pie' /usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-uClibc.so.0.9.32 -pie -z now -o a1 /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../Scrt1.o /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../crti.o /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/crtbeginS.o -L/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3 -L/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/lib -L/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../.. /tmp/cc6f9bmf.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/crtendS.o /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../crtn.o |
|||
05 Jul 2013, 17:27 |
|
sleepsleep 05 Jul 2013, 17:42
i hope this info is useful,
Code: format elf include '/fasm/examples/libcdemo/ccall.inc' section '.text' executable public main extrn getpid extrn printf main: call getpid ccall printf,msg,eax ret section '.data' writeable msg db 'hello world %d',0 Code: sleepserver:/# fasm a2.asm sleepserver:/# gcc -v a2.o -o a2 Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/lto-wrapper Target: i486-alpine-linux-uclibc Configured with: /home/buildozer/aports/main/gcc/src/gcc-4.7.3/configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --build=i486-alpine-linux-uclibc --host=i486-alpine-linux-uclibc --target=i486-alpine-linux-uclibc --with-pkgversion='Alpine 4.7.3' --disable-altivec --disable-build-with-cxx --disable-checking --disable-fixed-point --disable-libssp --disable-libstdcxx-pch --disable-multilib --disable-nls --disable-werror --enable-__cxa_atexit --enable-cld --enable-esp --enable-cloog-backend --enable-languages=c,c++,objc,java,go,fortran --enable-shared --enable-target-optspace --enable-tls --enable-threads --with-dynamic-linker=ld-uClibc.so.0.9.32 --with-dynamic-linker-prefix=/lib --with-system-zlib --without-system-libunwind Thread model: posix gcc version 4.7.3 (Alpine 4.7.3) COMPILER_PATH=/usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/:/usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/:/usr/libexec/gcc/i486-alpine-linux-uclibc/:/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/:/usr/lib/gcc/i486-alpine-linux-uclibc/:/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/bin/ LIBRARY_PATH=/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/:/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/lib/:/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-o' 'a2' '-mtune=i486' '-march=i486' '-fPIE' '-pie' /usr/libexec/gcc/i486-alpine-linux-uclibc/4.7.3/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-uClibc.so.0.9.32 -pie -z now -o a2 /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../Scrt1.o /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../crti.o /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/crtbeginS.o -L/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3 -L/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../../i486-alpine-linux-uclibc/lib -L/usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../.. a2.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/crtendS.o /usr/lib/gcc/i486-alpine-linux-uclibc/4.7.3/../../../crtn.o |
|||
05 Jul 2013, 17:42 |
|
sleepsleep 05 Jul 2013, 17:43
the generated executables above dont work with error,
Quote:
|
|||
05 Jul 2013, 17:43 |
|
Endre 08 Jul 2013, 08:17
I've got no more ideas. Try to ask about it on the Alpine linux forum. As I see Alpine linux is sort of embedded linux, and as such it may need some tweaking to make it fit for your needs. I can imagine that you have to enable/disable something in the kernel in this regard, but I don't know. But I'd be interested in, so if you got to know something then please let us know.
|
|||
08 Jul 2013, 08:17 |
|
sleepsleep 08 Jul 2013, 19:23
i got posted some question into their new forum and mailing list, no way to push things, gotta wait,
ok, will post updated info regarding this in future if i got found any sort of solutions, thanks for reply, Endre,. appreciate. |
|||
08 Jul 2013, 19:23 |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.