diff --git a/Makefile b/Makefile index 23a8afe..c72a468 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ CFLAGS += -O2 -MMD -Wall -Werror $(INCFLAGS) \ -Wno-main -U_FORTIFY_SOURCE -fvisibility=hidden CXXFLAGS += $(CFLAGS) -ffreestanding -fno-rtti -fno-exceptions ASFLAGS += -MMD $(INCFLAGS) -LDFLAGS += -z noexecstack +LDFLAGS += -z noexecstack $(addprefix -T, $(LDSCRIPTS)) ## 4. Arch-Specific Configurations @@ -123,13 +123,13 @@ $(LIBS): %: @$(MAKE) -s -C $(AM_HOME)/$* archive ### Rule (link): objects (`*.o`) and libraries (`*.a`) -> `IMAGE.elf`, the final ELF binary to be packed into image (ld) -$(IMAGE).elf: $(LINKAGE) +$(IMAGE).elf: $(LINKAGE) $(LDSCRIPTS) @echo \# Creating image [$(ARCH)] @echo + LD "->" $(IMAGE_REL).elf ifneq ($(filter $(ARCH),native),) - $(CXX) -o $@ -Wl,--whole-archive $^ -Wl,-no-whole-archive $(LDFLAGS_CXX) + $(CXX) -o $@ -Wl,--whole-archive $(LINKAGE) -Wl,-no-whole-archive $(LDFLAGS_CXX) else - @$(LD) $(LDFLAGS) -o $@ --start-group $^ --end-group + @$(LD) $(LDFLAGS) -o $@ --start-group $(LINKAGE) --end-group endif ### Rule (archive): objects (`*.o`) -> `ARCHIVE.a` (ar) diff --git a/scripts/platform/nemu.mk b/scripts/platform/nemu.mk index 6f1a061..1c5a395 100644 --- a/scripts/platform/nemu.mk +++ b/scripts/platform/nemu.mk @@ -9,8 +9,8 @@ AM_SRCS := platform/nemu/trm.c \ CFLAGS += -fdata-sections -ffunction-sections CFLAGS += -I$(AM_HOME)/am/src/platform/nemu/include -LDFLAGS += -T $(AM_HOME)/scripts/linker.ld \ - --defsym=_pmem_start=0x80000000 --defsym=_entry_offset=0x0 +LDSCRIPTS += $(AM_HOME)/scripts/linker.ld +LDFLAGS += --defsym=_pmem_start=0x80000000 --defsym=_entry_offset=0x0 LDFLAGS += --gc-sections -e _start NEMUFLAGS += -l $(shell dirname $(IMAGE).elf)/nemu-log.txt diff --git a/scripts/platform/npc.mk b/scripts/platform/npc.mk index ea8a34d..57c9f30 100644 --- a/scripts/platform/npc.mk +++ b/scripts/platform/npc.mk @@ -9,8 +9,8 @@ AM_SRCS := riscv/npc/start.S \ platform/dummy/mpe.c CFLAGS += -fdata-sections -ffunction-sections -LDFLAGS += -T $(AM_HOME)/scripts/linker.ld \ - --defsym=_pmem_start=0x80000000 --defsym=_entry_offset=0x0 +LDSCRIPTS += $(AM_HOME)/scripts/linker.ld +LDFLAGS += --defsym=_pmem_start=0x80000000 --defsym=_entry_offset=0x0 LDFLAGS += --gc-sections -e _start MAINARGS_MAX_LEN = 64 diff --git a/scripts/spike.mk b/scripts/spike.mk index 6147b99..54fa947 100644 --- a/scripts/spike.mk +++ b/scripts/spike.mk @@ -10,7 +10,7 @@ AM_SRCS := riscv/spike/trm.c \ platform/dummy/mpe.c \ CFLAGS += -fdata-sections -ffunction-sections -LDFLAGS += -T $(AM_HOME)/am/src/riscv/spike/linker.ld +LDSCRIPTS += $(AM_HOME)/am/src/riscv/spike/linker.ld LDFLAGS += --gc-sections -e _start CFLAGS += -DMAINARGS=\"$(mainargs)\"