Skip to content

Commit fe6007b

Browse files
committed
[build] Use CC as a linker
Signed-off-by: Pedro Falcato <[email protected]>
1 parent 8028512 commit fe6007b

File tree

10 files changed

+39
-20
lines changed

10 files changed

+39
-20
lines changed

arch/arm/rules.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ ARCH_COMPILEFLAGS += $(ARCH_$(ARCH)_COMPILEFLAGS)
325325
GLOBAL_COMPILEFLAGS += $(THUMBINTERWORK)
326326

327327
# set the max page size to something more reasonable (defaults to 64K or above)
328-
ARCH_LDFLAGS += -z max-page-size=4096
328+
ARCH_LDFLAGS += -Wl,-z,max-page-size=4096
329329

330330
# find the direct path to libgcc.a for our particular multilib variant
331331
LIBGCC := $(shell $(TOOLCHAIN_PREFIX)gcc $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(THUMBCFLAGS) -print-libgcc-file-name)

arch/arm/toolchain.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ ARCH_arm_COMPILEFLAGS += -march=armv7-r
111111
ARCH_arm_COMPILEFLAGS += -mcpu=$(ARM_CPU)
112112
ARCH_arm_COMPILEFLAGS += -mbig-endian
113113
ARCH_arm_COMPILEFLAGS += -mfpu=vfpv3-d16 -mfloat-abi=hard
114-
GLOBAL_MODULE_LDFLAGS += -EB
114+
GLOBAL_MODULE_LDFLAGS += -Wl,-EB
115115
endif
116116
ifeq ($(ARM_CPU),armemu)
117117
ARCH_arm_COMPILEFLAGS += -march=armv7-a

arch/arm64/rules.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ $(info TOOLCHAIN_PREFIX = $(TOOLCHAIN_PREFIX))
9494
ARCH_COMPILEFLAGS += $(ARCH_$(ARCH)_COMPILEFLAGS)
9595
ARCH_COMPILEFLAGS += -fno-omit-frame-pointer
9696

97-
ARCH_LDFLAGS += -z max-page-size=4096
97+
ARCH_LDFLAGS += -Wl,-z,max-page-size=4096
9898

9999
LIBGCC := $(shell $(TOOLCHAIN_PREFIX)gcc $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) -print-libgcc-file-name)
100100

arch/microblaze/rules.mk

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ LITTLE_ENDIAN ?= 0
3030

3131
ifneq ($(LITTLE_ENDIAN),0)
3232
ARCH_COMPILEFLAGS += -mlittle-endian
33-
ARCH_LDFLAGS += -EL
34-
GLOBAL_MODULE_LDFLAGS += -EL
33+
ARCH_LDFLAGS += -Wl,-EL
34+
GLOBAL_MODULE_LDFLAGS += -Wl,-EL
3535
endif
3636

3737
LIBGCC := $(shell $(TOOLCHAIN_PREFIX)gcc $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) $(GLOBAL_COMPILEFLAGS) -print-libgcc-file-name)
@@ -42,7 +42,9 @@ cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`";
4242

4343
ARCH_OPTFLAGS := -O2
4444

45-
ARCH_LDFLAGS += -relax
45+
# -L$(BUILDDIR) is needed so the linker can find the xilinx.ld it wants
46+
ARCH_LDFLAGS += -Wl,-relax -L$(BUILDDIR)
47+
GLOBAL_MODULE_LDFLAGS += -L$(BUILDDIR)
4648

4749
KERNEL_BASE ?= $(MEMBASE)
4850
KERNEL_LOAD_OFFSET ?= 0
@@ -54,9 +56,11 @@ GLOBAL_DEFINES += \
5456

5557
# potentially generated files that should be cleaned out with clean make rule
5658
GENERATED += \
57-
$(BUILDDIR)/linker.ld
59+
$(BUILDDIR)/linker.ld \
60+
$(BUILDDIR)/xilinx.ld
61+
62+
# Rules for generating the linker scripts
5863

59-
# rules for generating the linker
6064
$(BUILDDIR)/linker.ld: $(LOCAL_DIR)/linker.ld $(wildcard arch/*.ld) linkerscript.phony
6165
@echo generating $@
6266
@$(MKDIR)
@@ -66,6 +70,16 @@ $(BUILDDIR)/linker.ld: $(LOCAL_DIR)/linker.ld $(wildcard arch/*.ld) linkerscript
6670
linkerscript.phony:
6771
.PHONY: linkerscript.phony
6872

69-
LINKER_SCRIPT += $(BUILDDIR)/linker.ld
73+
# Note: This is all messy and horrible
74+
# GCC needs to find a xilinx.ld, we usually pass the LINKER_SCRIPT as -dT (default linker script), and so
75+
# does GCC when it can't find a -T option in the command line
76+
# Because of that, we pass the actual linker script as linker.ld
77+
78+
$(BUILDDIR)/xilinx.ld:
79+
$(NOECHO)touch $@
80+
81+
EXTRA_LINKER_SCRIPTS += $(BUILDDIR)/linker.ld
82+
83+
LINKER_SCRIPT += $(BUILDDIR)/xilinx.ld
7084

7185
include make/module.mk

arch/mips/rules.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ LITTLE_ENDIAN ?= 0
3232
ifneq ($(LITTLE_ENDIAN),0)
3333
ARCH_COMPILEFLAGS += -EL
3434
ARCH_ASFLAGS += -EL
35-
ARCH_LDFLAGS += -EL
36-
GLOBAL_MODULE_LDFLAGS += -EL
35+
ARCH_LDFLAGS += -Wl,-EL
36+
GLOBAL_MODULE_LDFLAGS += -Wl,-EL
3737
endif
3838

3939
ARCH_COMPILEFLAGS += -mno-gpopt

arch/or1k/rules.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`";
2525

2626
ARCH_OPTFLAGS := -O2
2727

28-
ARCH_LDFLAGS += -relax
28+
ARCH_LDFLAGS += -Wl,-relax
2929

3030
LIBGCC := $(shell $(TOOLCHAIN_PREFIX)gcc $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) -print-libgcc-file-name)
3131
$(info LIBGCC = $(LIBGCC))

arch/riscv/rules.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ endif
137137
ifeq ($(SUBARCH),32)
138138
ARCH_COMPILEFLAGS := -march=rv32imac -mabi=ilp32
139139
# override machine for ld -r
140-
GLOBAL_MODULE_LDFLAGS += -m elf32lriscv
140+
GLOBAL_MODULE_LDFLAGS += -Wl,-m,elf32lriscv
141141
else ifeq ($(SUBARCH),64)
142142
GLOBAL_DEFINES += IS_64BIT=1
143143
ARCH_COMPILEFLAGS := -march=rv64imac -mabi=lp64 -mcmodel=medany
144144
# override machine for ld -r
145-
GLOBAL_MODULE_LDFLAGS += -m elf64lriscv
145+
GLOBAL_MODULE_LDFLAGS += -Wl,-m,elf64lriscv
146146
else
147147
$(error SUBARCH not set or set to something unknown)
148148
endif
@@ -184,7 +184,7 @@ LINKER_SCRIPT += $(BUILDDIR)/linker-twosegment.ld
184184
# a paged sytem would.
185185
# NOTE: 8 seems to be about as far as you can go. experienced some extra stuffed words
186186
# when using 4.
187-
ARCH_LDFLAGS += -z max-page-size=8
187+
ARCH_LDFLAGS += -Wl,-z,max-page-size=8
188188
else
189189
GLOBAL_DEFINES += ARCH_RISCV_TWOSEGMENT=0
190190
LINKER_SCRIPT += $(BUILDDIR)/linker-onesegment.ld

arch/x86/rules.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ GLOBAL_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
9595
ARCH_COMPILEFLAGS += -fasynchronous-unwind-tables
9696
ARCH_COMPILEFLAGS += -gdwarf-2
9797
ARCH_COMPILEFLAGS += -fno-pic
98-
ARCH_LDFLAGS += -z max-page-size=4096
98+
ARCH_LDFLAGS += -Wl,-z,max-page-size=4096
9999

100100
ifeq ($(SUBARCH),x86-64)
101101
ARCH_COMPILEFLAGS += -fno-stack-protector

engine.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ endif
214214
# default to no ccache
215215
CCACHE ?=
216216
CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
217-
LD := $(TOOLCHAIN_PREFIX)ld
217+
LD := $(TOOLCHAIN_PREFIX)gcc
218218
OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
219219
OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
220220
CPPFILT := $(TOOLCHAIN_PREFIX)c++filt

make/build.mk

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# use linker garbage collection, if requested
22
ifeq ($(WITH_LINKER_GC),1)
33
GLOBAL_COMPILEFLAGS += -ffunction-sections -fdata-sections
4-
GLOBAL_LDFLAGS += --gc-sections
4+
GLOBAL_LDFLAGS += -Wl,--gc-sections
55
endif
66

7+
GLOBAL_LDFLAGS += -static -ffreestanding -nostartfiles -nostdlib -fuse-ld=bfd
8+
GLOBAL_MODULE_LDFLAGS += -static -ffreestanding -nostartfiles -nostdlib -fuse-ld=bfd
9+
710
ifneq (,$(EXTRA_BUILDRULES))
811
-include $(EXTRA_BUILDRULES)
912
endif
@@ -19,12 +22,14 @@ $(OUTELF).hex: $(OUTELF)
1922
$(info generating hex file: $@)
2023
$(NOECHO)$(OBJCOPY) -O ihex $< $@
2124

25+
comma = ,
26+
2227
$(OUTELF): $(ALLMODULE_OBJS) $(EXTRA_OBJS) $(LINKER_SCRIPT) $(EXTRA_LINKER_SCRIPTS)
2328
$(info linking $@)
2429
$(NOECHO)$(SIZE) -t --common $(sort $(ALLMODULE_OBJS)) $(EXTRA_OBJS)
25-
$(NOECHO)$(LD) $(GLOBAL_LDFLAGS) $(ARCH_LDFLAGS) -dT $(LINKER_SCRIPT) \
30+
$(NOECHO)$(LD) $(GLOBAL_LDFLAGS) $(ARCH_LDFLAGS) -Wl,--verbose -v -Wl,-dT$(LINKER_SCRIPT) \
2631
$(addprefix -T,$(EXTRA_LINKER_SCRIPTS)) \
27-
$(ALLMODULE_OBJS) $(EXTRA_OBJS) $(LIBGCC) -Map=$(OUTELF).map -o $@
32+
$(ALLMODULE_OBJS) $(EXTRA_OBJS) $(LIBGCC) -Wl,-Map=$(OUTELF).map -o $@
2833

2934
$(OUTELF).sym: $(OUTELF)
3035
$(info generating symbols: $@)

0 commit comments

Comments
 (0)