From b5573c5b51b3bdf38b7cea318cae41bd141f46e3 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 28 Jan 2020 00:00:52 +0900 Subject: [PATCH] sim: Fix nuttx.rel for macOS * ld doesn't have --start-groupi/--end-group things. As far as I know, it works that way by default. * objcopy with Mach-O support is not widely available. (GNU binutils seem to claim the support but it didn't actually work for me. llvm-objcopy --redefine-syms explicitly rejects Mach-O.) Instead, use -unexported_symbols_list linker flag to hide symbols to avoid conflicts with host symbols. --- arch/sim/src/Makefile | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/arch/sim/src/Makefile b/arch/sim/src/Makefile index b7f5196a57..8bd1f72748 100644 --- a/arch/sim/src/Makefile +++ b/arch/sim/src/Makefile @@ -195,8 +195,15 @@ endif # Override in Make.defs if linker is not 'ld' -LDSTARTGROUP ?= --start-group -LDENDGROUP ?= --end-group +ifeq ($(HOSTOS),Darwin) + LDSTARTGROUP ?= + LDENDGROUP ?= + LDUNEXPORTSYMBOLS ?= -unexported_symbols_list $(HOSTOS)-names.dat +else + LDSTARTGROUP ?= --start-group + LDENDGROUP ?= --end-group + LDUNEXPORTSYMBOLS ?= +endif EXTRA_LIBS ?= EXTRA_LIBPATHS ?= @@ -292,10 +299,15 @@ else $(Q) cp nuttx-names.dat $@ endif +Darwin-names.dat: nuttx-names.dat + $(Q) cat $^ | sed -e "s/^\([^[:space:]][^[:space:]]*\)[[:space:]].*/_\1/g" >$@ + nuttx.rel : libarch$(LIBEXT) board/libboard$(LIBEXT) $(HOSTOS)-names.dat $(LINKOBJS) $(Q) echo "LD: nuttx.rel" - $(Q) $(LD) -r $(LDLINKFLAGS) $(RELPATHS) $(EXTRA_LIBPATHS) -o $@ $(REQUIREDOBJS) $(LDSTARTGROUP) $(RELLIBS) $(EXTRA_LIBS) $(LDENDGROUP) + $(Q) $(LD) -r $(LDLINKFLAGS) $(RELPATHS) $(EXTRA_LIBPATHS) -o $@ $(REQUIREDOBJS) $(LDSTARTGROUP) $(RELLIBS) $(EXTRA_LIBS) $(LDENDGROUP) $(LDUNEXPORTSYMBOLS) +ifneq ($(HOSTOS),Darwin) $(Q) $(OBJCOPY) --redefine-syms=$(HOSTOS)-names.dat $@ +endif # Generate the final NuttX binary by linking the host-specific objects with the NuttX # specific objects (with munged names) @@ -327,7 +339,7 @@ export_startup: board/libboard$(LIBEXT) up_head.o $(HOSTOBJS) depend: .depend cleanrel: - $(Q) rm -f nuttx.rel GNU/Linux-names.dat Cygwin-names.dat + $(Q) rm -f nuttx.rel $(HOSTOS)-names.dat clean: cleanrel $(Q) if [ -e board/Makefile ]; then \