commit 2e929a1256a99b81e6ae15cb859b4172b7ee1256
parent 4cd0d9323f2a389bb7ff1a4a7495d998e5b98700
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 18 Oct 2023 11:23:00 +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, 13 insertions(+), 2 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): libaw.o
$(AR) -rc $@ $?
$(RANLIB) $@
+libaw.o: $(OBJ)
+ $(LD) -r $(OBJ) -o $@
+ $(OBJCOPY) $(OCPFLAGS) $@
+
.config: Makefile config.mk
@if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
echo "rsys $(RSYS_VERSION) not found"; exit 1; fi
@@ -96,7 +100,8 @@ uninstall:
all: build_library build_tests
clean: clean_test
- rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) .config .test aw.pc aw-local.pc
+ rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME)
+ rm -f .config .test aw.pc aw-local.pc libaw.o
distclean: clean
rm -f $(DEP) $(TEST_DEP)
diff --git a/config.mk b/config.mk
@@ -12,7 +12,9 @@ BUILD_TYPE = RELEASE
################################################################################
AR = ar
CC = cc
+LD = ld
PKG_CONFIG = pkg-config
+OBJCOPY = objcopy
RANLIB = ranlib
################################################################################
@@ -57,3 +59,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))