3

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?

SerHack
  • 153
  • 11
  • How do you build the C source code? How do you build the assembler code? What flags are you passing to the compiler respective the assembler? Please [edit] your question to include a copy-paste the full and complete commands you use. – Some programmer dude Jun 25 '21 at 09:07
  • Next time please show your code so a better diagnosis can be given. PIE is the most likely cause but without seeing your code, nobody can point out what part of your code causes this warning. – fuz Jun 25 '21 at 11:04
  • The warning is being generated at linking phase, pointing lines of function declaration. – SerHack Jun 25 '21 at 11:06
  • @SerHack Are you sure? Usually it should give you an address at which the problem occured. If you assemble with `-g`, you might also get a line number. – fuz Jun 25 '21 at 15:14
  • Nope, it does not give a line number. – SerHack Jun 26 '21 at 19:11

1 Answers1

2

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

SerHack
  • 153
  • 11
  • Related: [Understanding a DT\_TEXTREL warning](https://stackoverflow.com/q/76651605) re: what the warning is about and what a TEXTREL is. – Peter Cordes Jul 10 '23 at 17:10