GCC Assembly x86 relocation warning: creating DT_TEXTREL in a PIE

Viewed 221

i'm writing a project for university in Assembly x86 (32 bit) with AT&T syntax. During the course we compiled our source files with gnu gas and the command ld. Now i'm using GCC because i want to make an assembly function and call it from C program.

But when i started to compile with GCC i got these strange warnings, about linking and relocation.

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

Here is a small example of file which cause the warnings. Warnings happen only when i try to access/use the static variables declared in .data

.file "telemetry.s"

.data 
test: .string "Example"
 
.text
.globl telemetry
.type telemetry, @function
telemetry:
    pushl %ebp
    movl %esp, %ebp
    pushl %ebx

    leal test, %ebx # if i comment this line warnings wont happen

    popl %ebx
    popl %ebp
    ret

I get the warnings only with the gcc version which i'm currently using (11.2.0), on Ubuntu 22.04.01. Here's the commands:

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

If I assemble it with GAS and link with ld manually, I don't get the warnings.

An older version of gcc (7.5.0) also produces no warning (in a docker container Ubuntu 18.04).

So this could be a bug/problem of the current version of gcc, or what changed since then? Am I doing something wrong?

0 Answers
Related