Extern function declaration in Assembly produces a warning

Viewed 326

I'm calling an extern function that was developed in assembly using the follow snippet of code:

extern int myfunction();

Apart from the execution code, to declare a function in assembly, I'm using:

.section .text
.global myfunction
.type myfunction, @function

This should tell the compiler that assembly file contains a reference of the external function called myfunction. Then I compile the code, using the following commands:

gcc -m32 -o obj/main.o -c src/main.c
gcc -m32 -o obj/myfunction.o -c src/myfunction.s
gcc -o bin/myfunction obj/main.o obj/myfunction.o -m32 

When I'm compiling using GCC 10, a warning is being shown:

/usr/bin/ld: warning: relocation in read-only section `.text'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE

How can I suppress that warning?

1 Answers

Add the flag --no-pie to your build commands. This specifies the compiler not to generate a PIE (Position Independent Executable) file. PIE is commonly used for shared libraries, so that the same library code can be loaded in a location in each program address space where it does not overlap with other memory in use (for example, other shared libraries).

Related