relocation R_X86_64_32S against '.text' can not be used
Posted: Fri Jul 16, 2021 12:02 pm
Hello OSDev forum!
I got a problem about GDT table when I am trying to compile.
My makefile code:
Code that is causing relocation error
I am using gcc cross compiler like in GCC_Cross-Compiler tutorial
Do anyone knows what's wrong?
I got a problem about GDT table when I am trying to compile.
Code: Select all
gdt.o: relocation R_X86_64_32S against `.text' can not be used when making a PIE object; recompile with -fPIE
Code: Select all
INTERNALLDFLAGS := \
-fno-pic -fPIE \
-Wl,-static,-pie,--no-dynamic-linker,-ztext \
-static-pie \
-nostdlib \
-Tlinker.ld \
-z max-page-size=0x1000
INTERNALCFLAGS := \
-I${INCLUDE_DIR} \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
-fno-pic -fPIE \
-mno-80387 \
-mno-mmx \
-mno-3dnow \
-mno-red-zone
build: $(KERNEL)
$(KERNEL): $(OBJ)
$(CC) $(INTERNALLDFLAGS) $(OBJ) -o $@
%.o: %.c ${C_HEADERS}
$(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@
%.o: %.asm
${NASM} $< -f elf64 -o $@
Code: Select all
void init_gdt()
{
__lgdt(&g_gdt);
asm volatile(
"movq %%rsp, %%rax\n"
"pushq $16\n"
"pushq %%rax\n"
"pushfq\n"
"pushq $8\n"
"pushq $1f\n"
"iretq\n"
"1:\n"
"movw $16, %%ax\n"
"movw %%ax, %%ds\n"
"movw %%ax, %%es\n"
"movw %%ax, %%fs\n"
"movw %%ax, %%gs\n" ::
: "memory", "rax");
}
Do anyone knows what's wrong?