Re: Issue linking 32-bit GAS assembly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Hello
On Wed, Oct 17, 2018 at 12:37 PM Dutch Ingraham <stoa@xxxxxx> wrote:
>
> Hi all:
>
> I'm having a problem linking 32-bit GAS assembly code that references external
> C libraries on an up-to-date 64-bit Arch installation.
>
> I have enabled the 32-bit repositories and installed the multilib-devel group
> and lib32-glibc. I have updated the library cache with ldconfig and rebooted.
>
> The command to assemble is: <as --32 -o filename.o filename.s>.  Assembly
> succeeds.
>
> However, when linking using the command
> <ld -melf_i386 --dynamic-linker /lib32/ld-linux.so.2 -lc -o filename filename.o>
>
> the command fails with:
>         ld: skipping incompatible /usr/lib/libc.so when searching for -lc
>         ld: skipping incompatible /usr/lib/libc.a when searching for -lc
>         ld: cannot find -lc
>
> Note this linker command (or a hierarchy-appropriate one) seems standard, and
> succeeds on a 64-bit Debian OS.
>
> There is a fairly recent Forum question (but pre-dating the discontinuance of
> i686 support) regarding the same issue at
> https://bbs.archlinux.org/viewtopic.php?id=229235 which indicates the command
> should be:
>
> <ld -melf_i386 -shared -L /usr/lib32 -dynamic-linker /lib/ld-linux.so.2 -o \
> filename filename.o -lc>
>
> This command succeeds, insofar as the linker returns an exit code of 0. However,
> running the program (and all other similar programs) fails with "Illegal
> instruction (core dumped)." Assembling with debugging symbols and running a
> backtrace didn't enlighten me.
>
> Note that changing /lib/ld-linux to /usr/lib32/ld-linux in the command immediately
> above produces the same result, as confirmed by the output of <ldconfig -p>
>
> Anyone see something I've missed of have any suggestions?  Thanks.
>
>
> -----------
>
> Here is some simple code to test with:
>
>
> # paramtest2.s - Listing system environment variables
> .section .data
> output:
>    .asciz "%s\n"
> .section .text
> .globl _start
> _start:
>    movl %esp, %ebp
>    addl $12, %ebp
> loop1:
>    cmpl $0, (%ebp)
>    je endit
>    pushl (%ebp)
>    pushl $output
>    call printf
>    addl $12, %esp
>    addl $4, %ebp
>    loop loop1
> endit:
>    pushl $0
>    call exit


Here is what I ran to make your example working on my Arch Linux machine


sudo pacman -S lib32-glibc
as --32 -o asm.o asm.s
ld -melf_i386 --dynamic-linker /lib/ld-linux.so.2 -L/usr/lib32 -lc -o asm asm.o
./asm


The only difference that I specified -L (library search path) to make
sure the linked can find 32-bit version of libc.



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux