Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extern function declaration in Assembly produces a warning

Tags:

c

assembly

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?

like image 447
SerHack Avatar asked Jan 17 '26 12:01

SerHack


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).

like image 72
SerHack Avatar answered Jan 20 '26 04:01

SerHack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!