yosmo78
yosmo78

Reputation: 619

AS assembler ARM Raspberry PI 3 linking with C libraries?

I am learning how to program on my raspberry pi. When i compile I use the as and ld commands to compile and link. I want to link with libc and use malloc but not use gcc as my compiler. I tried linking with /usr/lib/arm-linux-gnueabihf/libc.so

Here is what I typed (edit):

as test.s -o test.o
ld -o test test.o /usr/lib/arm-linux-gnueabihf/libc.so
./test

it compiled and linked, but when I try to run it, it says test is not found

Here is test.s:

.global _start
.extern malloc

_start:
    mov R0, #4
    bl malloc
    mov R0, #0
    mov R7, #1
    svc 0
.end

Is this ok?
Or do I need to do something more?
Any help would be appreciated?

EDIT here is what I am doing (don't forget to initialize C if using some of its functions!):

ld -o test /usr/lib/arm-linux-gnueabihf/libc.so test.o -dynamic-linker /lib/ld-linux-armhf.so.3

Upvotes: 1

Views: 646

Answers (1)

FPK
FPK

Reputation: 2098

You have to pass the path to the dynamic linker to ld by -dynamic-linker /lib/ld-linux-armhf.so.3 else it uses /usr/lib/ld.so.1 which does not exist.

Note: While this produces an exectuable which can be run, I doubt it works properly as libc is used but not initalized.

Upvotes: 1

Related Questions