build: Use linker directly instead of going thru compiler; ensure we are buildable with an llvm toolchain
This commit is contained in:
parent
1e935e10d3
commit
e69f7429ce
@ -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)
|
||||
|
@ -25,6 +25,18 @@ SECTIONS
|
||||
bss_end = .;
|
||||
}
|
||||
|
||||
.symtab : {
|
||||
*(.symtab)
|
||||
}
|
||||
|
||||
.strtab : {
|
||||
*(.strtab)
|
||||
}
|
||||
|
||||
.shstrtab : {
|
||||
*(.shstrtab)
|
||||
}
|
||||
|
||||
/DISCARD/ : {
|
||||
*(*)
|
||||
}
|
||||
|
@ -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 \
|
||||
|
@ -44,6 +44,18 @@ SECTIONS
|
||||
bss_end = .;
|
||||
}
|
||||
|
||||
.symtab : {
|
||||
*(.symtab)
|
||||
}
|
||||
|
||||
.strtab : {
|
||||
*(.strtab)
|
||||
}
|
||||
|
||||
.shstrtab : {
|
||||
*(.shstrtab)
|
||||
}
|
||||
|
||||
/DISCARD/ : {
|
||||
*(*)
|
||||
}
|
||||
|
@ -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*)
|
||||
*(*)
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,18 @@ SECTIONS
|
||||
bss_end = .;
|
||||
}
|
||||
|
||||
.symtab : {
|
||||
*(.symtab)
|
||||
}
|
||||
|
||||
.strtab : {
|
||||
*(.strtab)
|
||||
}
|
||||
|
||||
.shstrtab : {
|
||||
*(.shstrtab)
|
||||
}
|
||||
|
||||
/DISCARD/ : {
|
||||
*(*)
|
||||
}
|
||||
|
@ -35,6 +35,18 @@ SECTIONS
|
||||
bss_end = .;
|
||||
}
|
||||
|
||||
.symtab : {
|
||||
*(.symtab)
|
||||
}
|
||||
|
||||
.strtab : {
|
||||
*(.strtab)
|
||||
}
|
||||
|
||||
.shstrtab : {
|
||||
*(.shstrtab)
|
||||
}
|
||||
|
||||
/DISCARD/ : {
|
||||
*(*)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user