0

Im trying to compile a nasm x86 assembly program that uses the c library. The code is

section .text
  global main
  extern printf

main:
  push msg
  mov eax, 0
  call printf

  add esp, 4

  ret


section .data
  msg db "Hello", 0xa, 0

Its a simple program that should print "Hello". Im trying to compile this with 2 commands

nasm -f elf main.asm gcc -m32 -o main main.o

However, running gcc -m32 -o main main.o gives some errors.

The errors are:

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: skipping incompatible /usr/lib/libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: cannot find libgcc_s.so.1
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/../../../libgcc_s.so.1 when searching for libgcc_s.so.1
/usr/bin/ld: skipping incompatible /usr/lib/libgcc_s.so.1 when searching for libgcc_s.so.1
collect2: error: ld returned 1 exit status

I tried to install gcc-multilib because I heard that it helps but I kept getting the same error. Ive also tried updating gcc but that also did not help anything.

EDIT: I fixed the errors! I had to install a 32 bit gcc library called lib32-gcc-libs and then it got fixed. However I still have 2 warnings.

main.o: warning: relocation in read-only section '.text'
warning: creating DT_TEXTREL in a PIE

What do these warnings mean and how do I fix them?

dareesome
  • 133
  • 1
  • 7
  • 1
    It sounds like 32-bit libraries are not installed. What Linux distribution are you using? – Nate Eldredge Jun 14 '21 at 21:32
  • I am using Arch Linux – dareesome Jun 14 '21 at 21:35
  • "_I tried to install `gcc-multilib`_": Did you just try or did you install? Did you search for a tutorial, and what did you find, did it work? – the busybee Jun 15 '21 at 09:13
  • I installs ``gcc-multilib``. I then tried to run the commands again, nothing changed – dareesome Jun 15 '21 at 11:03
  • In order to install 32 bit libraries on arch linux do you enable multilib in ``pacman.conf``? – dareesome Jun 15 '21 at 19:43
  • Try `call printf@PLT`. Modern distros are security-conscious and don't allow hard-coding addresses, which is why you get a relocation now. Or something like that. – o11c Jun 18 '21 at 19:41
  • Undefined reference to ``printf@PLT`` When I compile it with gcc – dareesome Jun 18 '21 at 20:33
  • [Understanding a DT\_TEXTREL warning](https://stackoverflow.com/q/76651605) / [Extern function declaration in Assembly produces a warning](https://stackoverflow.com/q/68128327) re: the TEXTREL warning. – Peter Cordes Jul 10 '23 at 13:59

0 Answers0