commit fcc70bc58645bdba726510d52c8fe0b6b9aa0180
parent 3ab4e6c6ae71f843a169ff70565b5b28556e02b7
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 30 Oct 2023 16:50:47 +0100
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
@@ -50,10 +50,14 @@ $(DEP) $(OBJ): config.mk
$(LIBNAME_SHARED): $(OBJ)
$(CC) $(CFLAGS) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(SOFLAGS) $(DPDC_LIBS)
-$(LIBNAME_STATIC): $(OBJ)
+$(LIBNAME_STATIC): libhtsky.o
$(AR) -rc $@ $?
$(RANLIB) $@
+libhtsky.o: $(OBJ)
+ $(LD) -r $(OBJ) -o $@
+ $(OBJCOPY) $(OCPFLAGS) $@
+
.config: config.mk
@if ! $(PKG_CONFIG) --atleast-version $(HTCP_VERSION) htcp; then \
echo "htcp $(HTCP_VERSION) not found" >&2; exit 1; fi
@@ -118,7 +122,7 @@ uninstall:
all: build_library
clean:
- rm -f $(OBJ) $(LIBNAME) .config htsky.pc
+ rm -f $(OBJ) $(LIBNAME) .config libhtsky.o htsky.pc
distclean: clean
rm -f $(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
@@ -91,3 +93,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))