commit 9e3163492783e6e9967f84b201abc35a3e9b731c
parent a65c6402dd1cb39557b6157c8b313de54582ac46
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 11 Oct 2023 17:07:10 +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 for... debugging purposes.
Diffstat:
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile
@@ -58,10 +58,14 @@ $(DEP) $(OBJ): config.mk
$(LIBNAME_SHARED): $(OBJ)
$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS)
-$(LIBNAME_STATIC): $(OBJ)
+$(LIBNAME_STATIC): librnatm.o
$(AR) -rc $@ $?
$(RANLIB) $@
+librnatm.o: $(OBJ)
+ $(LD) -r $(OBJ) -o $@
+ $(OBJCOPY) $(OCPFLAGS) $@
+
.config: config.mk
@if ! $(PKG_CONFIG) --atleast-version $(RNSF_VERSION) rnsf; then \
echo "rnsf $(RNSF_VERSION) not found" >&2; exit 1; fi
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
@@ -130,3 +132,7 @@ LDFLAGS_RELEASE = -s $(LDFLAGS_HARDENED)
LDFLAGS_SO = $(LDFLAGS_$(BUILD_TYPE)) -shared -Wl,--no-undefined
LDFLAGS_EXE = $(LDFLAGS_$(BUILD_TYPE)) -pie
+
+OCPFLAGS_DEBUG = --localize-hidden
+OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded
+OCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE))