commit 6f68ea147c8f99fc481b167d0e0c555c6dcac90e
parent 315786ec985b0b58f9e8d6e7312c88b9d3680956
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 27 Oct 2023 16:10:34 +0200
Partially link static library object files
Make hidden symbols local to the relocatable object to avoid conflicts
with internal symbols in another static library. In release mode, delete
all symbols not required for relocation processing, but keep them in
debug mode.
Diffstat:
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
@@ -42,10 +42,14 @@ $(DEP) $(OBJ): config.mk
$(LIBNAME_SHARED): $(OBJ)
$(CC) $(CFLAGS) $(RSYS_CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(SOFLAGS) $(RSYS_LIBS)
-$(LIBNAME_STATIC): $(OBJ)
+$(LIBNAME_STATIC): libscmap.o
$(AR) -rc $@ $?
$(RANLIB) $@
+libscmap.o: $(OBJ)
+ $(LD) -r $(OBJ) -o $@
+ $(OBJCOPY) $(OCPFLAGS) $@
+
.config: config.mk
@if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi
@@ -94,7 +98,8 @@ uninstall:
all: build_library build_tests
clean: clean_test
- rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) .config .test scmap.pc scmap-local.pc
+ rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME)
+ rm -f .config .test libscmap.o scmap.pc scmap-local.pc
distclean: clean
rm -f $(DEP) $(TEST_DEP)
diff --git a/config.mk b/config.mk
@@ -12,6 +12,8 @@ BUILD_TYPE = RELEASE
################################################################################
AR = ar
CC = cc
+LD = ld
+OBJCOPY = objcopy
PKG_CONFIG = pkg-config
RANLIB = ranlib
@@ -22,7 +24,7 @@ PCFLAGS_SHARED =
PCFLAGS_STATIC = --static
PCFLAGS = $(PCFLAGS_$(LIB_TYPE))
-RSYS_VERSION=0.9
+RSYS_VERSION = 0.9
RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys)
RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys)
@@ -58,3 +60,7 @@ SOFLAGS = -shared -Wl,--no-undefined
LDFLAGS_DEBUG =
LDFLAGS_RELEASE = -s
LDFLAGS = $(LDFLAGS_$(BUILD_TYPE))
+
+OCPFLAGS_DEBUG = --localize-hidden
+OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded
+OCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE))