From 992387539f26de1aeb2cdca62d85fddbde27b798 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 18 Jan 2024 08:01:49 +0000 Subject: build system: more clang/llvm tweaks Linkers associated with clang/llvm may not support the -r option. This is used to create built-in.o object files. It turns out that all such files in busybox-w32 are either empty or only contain one object file. The first case is already supported and the second can be handled by simply copying the object file to built-in.o. The linker is therefore never invoked with the -r option. One adjustment is required: the workaround adopted for GitHub issue #200 linked the dummy C file with the resource object file. This is no longer done so only one object file is used. Since it was the linking that broke the resource file, copying it is an equally effective fix for the issue. Some old linkers don't support the --warn-common option. The lack of this option was being detected but it was still sometimes used. --- scripts/Makefile.build | 11 +++++++++++ scripts/trylink | 2 +- win32/resources/Kbuild.src | 1 - win32/resources/dummy.c | 2 -- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 5eac45f91..2a9f451f3 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -254,11 +254,22 @@ $(sort $(subdir-obj-y)): $(subdir-ym) ; # ifdef builtin-target quiet_cmd_link_o_target = LD $@ +ifeq ($(CONFIG_PLATFORM_POSIX),y) # If the list of objects to link is empty, just create an empty built-in.o # -nostdlib is added to make "make LD=gcc ..." work (some people use that) cmd_link_o_target = $(if $(strip $(obj-y)),\ $(LD) -nostdlib $(ld_flags) -r -o $@ $(filter $(obj-y), $^),\ rm -f $@; $(AR) rcs $@) +else +# In default builds of busybox-w32 all builtin targets have either +# zero or one object files. In the latter case copy the object to +# the target. This avoids the need to use the linker: the llvm +# linker doesn't support the -r option. +cmd_link_o_target = $(intcmp $(words $(obj-y)),1,\ + rm -f $@; $(AR) rcs $@,\ + cp $(obj-y) $@,\ + $(LD) -nostdlib $(ld_flags) -r -o $@ $(filter $(obj-y), $^)) +endif $(builtin-target): $(obj-y) FORCE $(call if_changed,link_o_target) diff --git a/scripts/trylink b/scripts/trylink index 2255deee7..776fd484a 100755 --- a/scripts/trylink +++ b/scripts/trylink @@ -96,7 +96,7 @@ fi START_GROUP="-Wl,--start-group" END_GROUP="-Wl,--end-group" INFO_OPTS() { - echo "-Wl,--warn-common -Wl,-Map,$EXE.map -Wl,--verbose" + echo "$SORT_COMMON -Wl,-Map,$EXE.map -Wl,--verbose" } # gold may not support --sort-common (yet) diff --git a/win32/resources/Kbuild.src b/win32/resources/Kbuild.src index e2d884e98..d056a5964 100644 --- a/win32/resources/Kbuild.src +++ b/win32/resources/Kbuild.src @@ -7,7 +7,6 @@ obj-y := obj-$(CONFIG_FEATURE_RESOURCES) += resources.o -obj-$(CONFIG_FEATURE_RESOURCES) += dummy.o # return commit level if available or 0 bb_level = $(or $(word 2,$(subst -, ,$1)),0) diff --git a/win32/resources/dummy.c b/win32/resources/dummy.c index 2d4b87680..e69de29bb 100644 --- a/win32/resources/dummy.c +++ b/win32/resources/dummy.c @@ -1,2 +0,0 @@ -extern void wibble(void); -void wibble(void) {} -- cgit v1.2.3-55-g6feb