1

here is something super simple:

My code (p1.s):

    .intel_syntax noprefix
.arch i386
.data
poruka:
    .asciz "Zdravo svete!\n"
kraj_poruke:

.equ duzina_poruke, kraj_poruke - poruka

.text
.extern write
.extern exit
.globl _start

_start:
push duzina_poruke
push offset poruka
push 1
call write
add esp, 12

push 0
call exit

.end

The commands I use to assemble and link the files:

as -o p1.o p1.s
ld -o p1 -dynamic-linker /lib/ld-linux.so.2 p1.o -l c

After these commands, I have the p1.s, p1.o and p1 files all in the directory where I want them.

The error I get:

bash ./p1 : Accessing a corrupted shared library.

Why? :D Thanks in advance!

Could someone please explain to me why this doesn't work? Thanks in advance! :)

Jester
  • 56,577
  • 4
  • 81
  • 125
Slavko Budic
  • 19
  • 1
  • 2

1 Answers1

1

This happens if you are on a 64 bit system. If you want to create a 32 bit program then use as --32 and ld -melf_i386. Also note that if you want to use libc you should use entry point main not _start and use gcc -m32 to compile and link so everything gets set up correctly and you avoid such mysterious errors.

Jester
  • 56,577
  • 4
  • 81
  • 125
  • Hey, I've tried (btw, yes I'm on a 64bit system): ld -melf_i386 -dynamic-linker /lib/ld-linux.so.2 p1.o -l c but now I get the error: ld: cannot find -lc whats up with that – Slavko Budic Mar 29 '15 at 17:59
  • You don't have the 32 bit C library installed. – Jester Mar 29 '15 at 18:00