[Concept,12/18] ulib: Makefile: Create a library with renamed symbols

Message ID 20250909151824.2327219-13-sjg@u-boot.org
State New
Headers
Series ulib: Complete initial U-Boot library |

Commit Message

Simon Glass Sept. 9, 2025, 3:18 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Add a way to create a .ulib-objs file which contains all of the object
files from the build, but with symbols renamed according to the
rename.syms file.

The file excludes main() which is present in the sandbox build, so that
programs which link with libu-boot can provide their own main()

For now this file is not used.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 Makefile | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
  

Patch

diff --git a/Makefile b/Makefile
index cfd24de82d5..f6527cca136 100644
--- a/Makefile
+++ b/Makefile
@@ -1859,6 +1859,25 @@  ifeq ($(CONFIG_RISCV),y)
 	@tools/prelink-riscv $@
 endif
 
+# Common step: create archive and prepare modified object files
+quiet_cmd_ulib-objs = OBJS    $@
+      cmd_ulib-objs = \
+	rm -f $@.tmp $@.objlist $@; \
+	$(AR) rcT $@.tmp $(u-boot-init) $(u-boot-main) \
+		$(u-boot-keep-syms-lto); \
+	$(AR) t $@.tmp | grep -v "arch/sandbox/cpu/main\.o$$" > $@.objlist; \
+	mkdir -p $@.objdir; \
+	$(PYTHON3) $(srctree)/scripts/build_api.py \
+		$(srctree)/lib/ulib/rename.syms \
+		--redefine $$(cat $@.objlist) --output-dir $@.objdir \
+		$(if $(filter -j%,$(MAKEFLAGS)),--jobs $(patsubst -j%,%,$(filter -j%,$(MAKEFLAGS)))) \
+		> $@; \
+	rm -f $@.tmp $@.objlist
+
+.ulib-objs: $(u-boot-init) $(u-boot-main) $(u-boot-keep-syms-lto) \
+		$(srctree)/lib/ulib/rename.syms FORCE
+	$(call if_changed,ulib-objs)
+
 # Build U-Boot as a shared library
 quiet_cmd_libu-boot.so = LD      $@
       cmd_libu-boot.so = $(CC) -shared -o $@ -Wl,--build-id=none \