commit abf973b520cd5f33f0915a40bf89bb54a3b07b90
parent 3c58bf38b30beda2cc3f6d4acd282356841a364f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 19 Oct 2023 15:45:45 +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
@@ -46,10 +46,14 @@ $(DEP) $(OBJ): config.mk
$(LIBNAME_SHARED): $(OBJ)
$(CC) $(CFLAGS) $(DPDC_CFLAGS) -fopenmp -o $@ $(OBJ) $(LDFLAGS) $(SOFLAGS) $(DPDC_LIBS)
-$(LIBNAME_STATIC): $(OBJ)
+$(LIBNAME_STATIC): libsmc.o
$(AR) -rc $@ $?
$(RANLIB) $@
+libsmc.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
@@ -104,7 +108,8 @@ uninstall:
all: build_library build_tests
clean: clean_test
- rm -f $(OBJ) $(TEST_OBJ) $(TEST_OBJ_S3D) $(LIBNAME) .config .test image.ppm smc.pc smc-local.pc
+ rm -f $(OBJ) $(TEST_OBJ) $(TEST_OBJ_S3D) $(LIBNAME)
+ rm -f .config .test image.ppm libsmc.o smc.pc smc-local.pc
distclean: clean
rm -f $(DEP) $(TEST_DEP) $(TEST_DEP_S3D)
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
@@ -69,3 +71,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))