build: Use linker directly instead of going thru compiler; ensure we are buildable with an llvm toolchain
diff --git a/decompressor/Makefile b/decompressor/Makefile
index 1e5d319a..015e336d 100644
--- a/decompressor/Makefile
+++ b/decompressor/Makefile
@@ -7,16 +7,20 @@ endif
TOOLCHAIN = x86_64-elf
TOOLCHAIN_CC = $(TOOLCHAIN)-gcc
+TOOLCHAIN_LD = $(TOOLCHAIN)-ld
TOOLCHAIN_OBJCOPY = $(TOOLCHAIN)-objcopy
ifeq ($(shell which $(TOOLCHAIN_CC)), )
TOOLCHAIN_CC := gcc
endif
+ifeq ($(shell which $(TOOLCHAIN_LD)), )
+TOOLCHAIN_LD := ld
+endif
ifeq ($(shell which $(TOOLCHAIN_OBJCOPY)), )
TOOLCHAIN_OBJCOPY := objcopy
endif
-CFLAGS = -flto -Os -pipe -Wall -Wextra -Werror
+CFLAGS = -Os -pipe -Wall -Wextra -Werror
INTERNAL_CFLAGS = \
-m32 \
@@ -36,16 +40,11 @@ INTERNAL_CFLAGS = \
-MMD \
-I.
-LDFLAGS = -flto -Os
+LDFLAGS =
INTERNAL_LDFLAGS = \
- -m32 \
- -march=i386 \
- -Wl,-melf_i386 \
+ -melf_i386 \
-nostdlib \
- -no-pie \
- -fno-pic \
- -fno-pie \
-z max-page-size=0x1000 \
-static \
-Tlinker.ld
@@ -65,7 +64,7 @@ builddir:
for i in $(OBJ); do mkdir -p `dirname $$i`; done
$(BUILDDIR)/decompressor.bin: $(OBJ)
- $(TOOLCHAIN_CC) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $(BUILDDIR)/decompressor.elf
+ $(TOOLCHAIN_LD) $(OBJ) $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $(BUILDDIR)/decompressor.elf
$(TOOLCHAIN_OBJCOPY) -O binary $(BUILDDIR)/decompressor.elf $@
-include $(HEADER_DEPS)
diff --git a/decompressor/linker.ld b/decompressor/linker.ld
index 707bddf5..4170047b 100644
--- a/decompressor/linker.ld
+++ b/decompressor/linker.ld
@@ -25,6 +25,18 @@ SECTIONS
bss_end = .;
}
+ .symtab : {
+ *(.symtab)
+ }
+
+ .strtab : {
+ *(.strtab)
+ }
+
+ .shstrtab : {
+ *(.shstrtab)
+ }
+
/DISCARD/ : {
*(*)
}
diff --git a/stage23/Makefile b/stage23/Makefile
index f35764bb..6d7aac9a 100644
--- a/stage23/Makefile
+++ b/stage23/Makefile
@@ -16,6 +16,7 @@ endif
TOOLCHAIN = x86_64-elf
TOOLCHAIN_CC = $(TOOLCHAIN)-gcc
+TOOLCHAIN_LD = $(TOOLCHAIN)-ld
TOOLCHAIN_OBJCOPY = $(TOOLCHAIN)-objcopy
TOOLCHAIN_OBJDUMP = $(TOOLCHAIN)-objdump
TOOLCHAIN_READELF = $(TOOLCHAIN)-readelf
@@ -23,6 +24,9 @@ TOOLCHAIN_READELF = $(TOOLCHAIN)-readelf
ifeq ($(shell which $(TOOLCHAIN_CC)), )
TOOLCHAIN_CC := gcc
endif
+ifeq ($(shell which $(TOOLCHAIN_LD)), )
+TOOLCHAIN_LD := ld
+endif
ifeq ($(shell which $(TOOLCHAIN_OBJCOPY)), )
TOOLCHAIN_OBJCOPY := objcopy
endif
@@ -88,32 +92,25 @@ ifeq ($(TARGET), uefi)
-mno-red-zone
endif
-LDFLAGS = -O3 -g
+LDFLAGS =
INTERNAL_LDFLAGS := \
- -fno-pic \
- -fno-lto \
-nostdlib \
-z max-page-size=0x1000
ifeq ($(TARGET), bios)
INTERNAL_LDFLAGS += \
- -m32 \
- -march=i386 \
- -fno-pie \
- -Wl,-melf_i386 \
- -static \
- -no-pie
+ -melf_i386 \
+ -static
endif
ifeq ($(TARGET), uefi)
INTERNAL_LDFLAGS += \
- -m64 \
- -march=x86-64 \
- -fpie \
- -Wl,-melf_x86_64 \
- -Wl,-static,-pie,--no-dynamic-linker,-ztext \
- -static-pie
+ -melf_x86_64 \
+ -static \
+ -pie \
+ --no-dynamic-linker \
+ -ztext
endif
.PHONY: all clean builddir
@@ -175,18 +172,18 @@ $(BUILDDIR)/limine.sys: $(BUILDDIR)/limine.elf
$(TOOLCHAIN_OBJCOPY) -O binary $< $@
$(BUILDDIR)/limine_stage2only.elf: $(OBJ)
- $(TOOLCHAIN_CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_stage2only.ld -o $@ || \
+ $(TOOLCHAIN_LD) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_stage2only.ld -o $@ || \
( echo "This error may mean that stage 2 was trying to use stage 3 symbols before loading stage 3" && \
false )
$(BUILDDIR)/limine_nomap.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o $(BUILDDIR)/stage2.map.o
- $(TOOLCHAIN_CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_nomap.ld -o $@
+ $(TOOLCHAIN_LD) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_nomap.ld -o $@
$(BUILDDIR)/limine.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o $(BUILDDIR)/stage2.map.o $(BUILDDIR)/full.map.o
- $(TOOLCHAIN_CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker.ld -o $@
+ $(TOOLCHAIN_LD) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker.ld -o $@
$(BUILDDIR)/limine_dbg.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o $(BUILDDIR)/stage2.map.o $(BUILDDIR)/full.map.o
- $(TOOLCHAIN_CC) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_dbg.ld -o $@
+ $(TOOLCHAIN_LD) $^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -Tlinker_dbg.ld -o $@
endif
@@ -201,7 +198,7 @@ $(BUILDDIR)/BOOTX64.EFI: $(BUILDDIR)/limine_efi.elf
$(TOOLCHAIN_OBJCOPY) -j .text -j .sdata -j .data -j .dynamic -j .dynsym -j .rel -j .rela -j .rel.* -j .rela.* -j .reloc --target efi-app-x86_64 --subsystem=10 $< $@
$(BUILDDIR)/limine_efi_nomap.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o
- $(TOOLCHAIN_CC) \
+ $(TOOLCHAIN_LD) \
-Tlinker_uefi_nomap.ld \
../gnu-efi/gnuefi/crt0-efi-x86_64.o \
../gnu-efi/gnuefi/libgnuefi.a \
@@ -209,7 +206,7 @@ $(BUILDDIR)/limine_efi_nomap.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_
$^ $(LDFLAGS) $(INTERNAL_LDFLAGS) -o $@
$(BUILDDIR)/limine_efi.elf: $(OBJ) $(BUILDDIR)/font.o $(BUILDDIR)/sys/smp_trampoline.o $(BUILDDIR)/full.map.o
- $(TOOLCHAIN_CC) \
+ $(TOOLCHAIN_LD) \
-Tlinker_uefi.ld \
../gnu-efi/gnuefi/crt0-efi-x86_64.o \
../gnu-efi/gnuefi/libgnuefi.a \
diff --git a/stage23/linker.ld b/stage23/linker.ld
index 3bb85e3b..2b91d55a 100644
--- a/stage23/linker.ld
+++ b/stage23/linker.ld
@@ -44,6 +44,18 @@ SECTIONS
bss_end = .;
}
+ .symtab : {
+ *(.symtab)
+ }
+
+ .strtab : {
+ *(.strtab)
+ }
+
+ .shstrtab : {
+ *(.shstrtab)
+ }
+
/DISCARD/ : {
*(*)
}
diff --git a/stage23/linker_dbg.ld b/stage23/linker_dbg.ld
index 52d96bb6..9e009aab 100644
--- a/stage23/linker_dbg.ld
+++ b/stage23/linker_dbg.ld
@@ -44,7 +44,67 @@ SECTIONS
bss_end = .;
}
+ .symtab : {
+ *(.symtab)
+ }
+
+ .strtab : {
+ *(.strtab)
+ }
+
+ .shstrtab : {
+ *(.shstrtab)
+ }
+
+ .debug_aranges : {
+ *(.debug_aranges)
+ }
+
+ .debug_pubnames : {
+ *(.debug_pubnames)
+ }
+
+ .debug_info : {
+ *(.debug_info)
+ }
+
+ .debug_abbrev : {
+ *(.debug_abbrev)
+ }
+
+ .debug_line : {
+ *(.debug_line)
+ }
+
+ .debug_loclists : {
+ *(.debug_loclists)
+ }
+
+ .debug_rnglists : {
+ *(.debug_rnglists)
+ }
+
+ .debug_frame : {
+ *(.debug_frame)
+ }
+
+ .debug_loc : {
+ *(.debug_loc)
+ }
+
+ .debug_ranges : {
+ *(.debug_ranges)
+ }
+
+ .debug_str : {
+ *(.debug_str)
+ }
+
+ .debug_line_str : {
+ *(.debug_line_str)
+ }
+
/DISCARD/ : {
- *(.eh_frame*)
+ *(*)
}
}
diff --git a/stage23/linker_nomap.ld b/stage23/linker_nomap.ld
index f5bbead9..365ef5ec 100644
--- a/stage23/linker_nomap.ld
+++ b/stage23/linker_nomap.ld
@@ -44,6 +44,18 @@ SECTIONS
bss_end = .;
}
+ .symtab : {
+ *(.symtab)
+ }
+
+ .strtab : {
+ *(.strtab)
+ }
+
+ .shstrtab : {
+ *(.shstrtab)
+ }
+
/DISCARD/ : {
*(*)
}
diff --git a/stage23/linker_stage2only.ld b/stage23/linker_stage2only.ld
index f85fa3fc..ccadc660 100644
--- a/stage23/linker_stage2only.ld
+++ b/stage23/linker_stage2only.ld
@@ -35,6 +35,18 @@ SECTIONS
bss_end = .;
}
+ .symtab : {
+ *(.symtab)
+ }
+
+ .strtab : {
+ *(.strtab)
+ }
+
+ .shstrtab : {
+ *(.shstrtab)
+ }
+
/DISCARD/ : {
*(*)
}
