Skip to content

Commit 2d193b3

Browse files
committed
Use CC as a linker
Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
1 parent 3dff26a commit 2d193b3

File tree

10 files changed

+37
-20
lines changed

10 files changed

+37
-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
@@ -96,7 +96,7 @@ ARCH_COMPILEFLAGS += -fno-omit-frame-pointer
9696
ARCH_COMPILEFLAGS_NOFLOAT := -mgeneral-regs-only
9797
ARCH_COMPILEFLAGS_FLOAT :=
9898

99-
ARCH_LDFLAGS += -z max-page-size=4096
99+
ARCH_LDFLAGS += -Wl,-z,max-page-size=4096
100100

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

arch/microblaze/rules.mk

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

2929
ifneq ($(LITTLE_ENDIAN),0)
3030
ARCH_COMPILEFLAGS += -mlittle-endian
31-
ARCH_LDFLAGS += -EL
32-
GLOBAL_MODULE_LDFLAGS += -EL
31+
ARCH_LDFLAGS += -Wl,-EL
32+
GLOBAL_MODULE_LDFLAGS += -Wl,-EL
3333
endif
3434

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

4141
ARCH_OPTFLAGS := -O2
4242

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

4547
KERNEL_BASE ?= $(MEMBASE)
4648
KERNEL_LOAD_OFFSET ?= 0
@@ -52,9 +54,11 @@ GLOBAL_DEFINES += \
5254

5355
# potentially generated files that should be cleaned out with clean make rule
5456
GENERATED += \
55-
$(BUILDDIR)/linker.ld
57+
$(BUILDDIR)/linker.ld \
58+
$(BUILDDIR)/xilinx.ld
59+
60+
# Rules for generating the linker scripts
5661

57-
# rules for generating the linker
5862
$(BUILDDIR)/linker.ld: $(LOCAL_DIR)/linker.ld $(wildcard arch/*.ld) linkerscript.phony
5963
@echo generating $@
6064
@$(MKDIR)
@@ -64,6 +68,16 @@ $(BUILDDIR)/linker.ld: $(LOCAL_DIR)/linker.ld $(wildcard arch/*.ld) linkerscript
6468
linkerscript.phony:
6569
.PHONY: linkerscript.phony
6670

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

6983
include make/module.mk

arch/mips/rules.mk

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

3838
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
@@ -149,7 +149,7 @@ ifeq ($(SUBARCH),32)
149149
endif
150150

151151
# override machine for ld -r
152-
GLOBAL_MODULE_LDFLAGS += -m elf32lriscv
152+
GLOBAL_MODULE_LDFLAGS += -Wl,-m,elf32lriscv
153153
else ifeq ($(SUBARCH),64)
154154
GLOBAL_DEFINES += IS_64BIT=1
155155

@@ -163,7 +163,7 @@ else ifeq ($(SUBARCH),64)
163163
endif
164164

165165
# override machine for ld -r
166-
GLOBAL_MODULE_LDFLAGS += -m elf64lriscv
166+
GLOBAL_MODULE_LDFLAGS += -Wl,-m,elf64lriscv
167167
else
168168
$(error SUBARCH not set or set to something unknown)
169169
endif
@@ -213,7 +213,7 @@ LINKER_SCRIPT += $(BUILDDIR)/linker-twosegment.ld
213213
# a paged sytem would.
214214
# NOTE: 8 seems to be about as far as you can go. experienced some extra stuffed words
215215
# when using 4.
216-
ARCH_LDFLAGS += -z max-page-size=8
216+
ARCH_LDFLAGS += -Wl,-z,max-page-size=8
217217
else
218218
GLOBAL_DEFINES += ARCH_RISCV_TWOSEGMENT=0
219219
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
@@ -218,7 +218,7 @@ endif
218218
# default to no ccache
219219
CCACHE ?=
220220
CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
221-
LD := $(TOOLCHAIN_PREFIX)ld
221+
LD := $(TOOLCHAIN_PREFIX)gcc
222222
OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
223223
OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
224224
CPPFILT := $(TOOLCHAIN_PREFIX)c++filt

make/build.mk

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
WITH_LINKER_GC ?= false
33
ifeq (true,$(call TOBOOL,$(WITH_LINKER_GC)))
44
GLOBAL_COMPILEFLAGS += -ffunction-sections -fdata-sections
5-
GLOBAL_LDFLAGS += --gc-sections
5+
GLOBAL_LDFLAGS += -Wl,--gc-sections
66
GLOBAL_DEFINES += LINKER_GC=1
77
endif
88

9+
GLOBAL_LDFLAGS += -static -ffreestanding -nostartfiles -nostdlib -fuse-ld=bfd
10+
GLOBAL_MODULE_LDFLAGS += -static -ffreestanding -nostartfiles -nostdlib -fuse-ld=bfd
11+
912
ifneq (,$(EXTRA_BUILDRULES))
1013
-include $(EXTRA_BUILDRULES)
1114
endif
@@ -24,9 +27,9 @@ $(OUTELF).hex: $(OUTELF)
2427
$(OUTELF): $(ALLMODULE_OBJS) $(EXTRA_OBJS) $(LINKER_SCRIPT) $(EXTRA_LINKER_SCRIPTS)
2528
$(info linking $@)
2629
$(NOECHO)$(SIZE) -t --common $(sort $(ALLMODULE_OBJS)) $(EXTRA_OBJS)
27-
$(NOECHO)$(LD) $(GLOBAL_LDFLAGS) $(ARCH_LDFLAGS) -dT $(LINKER_SCRIPT) \
30+
$(NOECHO)$(LD) $(GLOBAL_LDFLAGS) $(ARCH_LDFLAGS) -Wl,-dT$(LINKER_SCRIPT) \
2831
$(addprefix -T,$(EXTRA_LINKER_SCRIPTS)) \
29-
$(ALLMODULE_OBJS) $(EXTRA_OBJS) $(LIBGCC) -Map=$(OUTELF).map -o $@
32+
$(ALLMODULE_OBJS) $(EXTRA_OBJS) $(LIBGCC) -Wl,-Map=$(OUTELF).map -o $@
3033

3134
$(OUTELF).sym: $(OUTELF)
3235
$(info generating symbols: $@)

0 commit comments

Comments
 (0)