commit ad4e05fe6223f0777912d45531fedfbd77710bde
parent bc124e21ba3107b8b91095fb877283cc3cc8efa7
Author: vaplv <vaplv@free.fr>
Date: Wed, 18 Oct 2023 09:14:40 +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, 12 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
@@ -56,10 +56,14 @@ $(DEP) $(OBJ): config.mk
$(LIBNAME_SHARED): $(OBJ)
$(CC) $(CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(SOFLAGS) $(LIBS)
-$(LIBNAME_STATIC): $(OBJ)
+$(LIBNAME_STATIC): librsys.o
$(AR) -rc $@ $?
$(RANLIB) $@
+librsys.o: $(OBJ)
+ $(LD) -r $(OBJ) -o $@
+ $(OBJCOPY) $(OCPFLAGS) $@
+
.SUFFIXES: .c .d .o
.c.d:
@$(CC) $(CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
@@ -170,7 +174,7 @@ uninstall:
all: build_library build_tests
clean: clean_test
- rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME)
+ rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) librsys.o
rm -f rsys.pc rsys-local.pc
rm -f libtest_lib.so test_lib.o
rm -f .test rsys.pc .test.ppm test_text_reader.txt test.ppm
diff --git a/config.mk b/config.mk
@@ -12,6 +12,8 @@ BUILD_TYPE = RELEASE
################################################################################
CC = cc
AR = ar
+LD = ld
+OBJCOPY = objcopy
PKG_CONFIG = pkg-config
RANLIB = ranlib
@@ -52,3 +54,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))