Skip to content

Commit b0bc902

Browse files
author
Luca Toniolo
committed
build: Filter rtapi module version scripts to defined symbols only
rtapi_app.h unconditionally declares EXPORT_SYMBOL(rtapi_app_main) and EXPORT_SYMBOL(rtapi_app_exit), causing every module to list both names in its generated linker version script. Modules that only implement rtapi_app_main (e.g. hal/components/enum.c) then triggered lld's --no-undefined-version (default since LLD 17, see LLVM D135402): ld.lld: error: version script assignment of 'global' to symbol 'rtapi_app_exit' failed: symbol not defined Intersect the exported-name list with the actual defined symbols from nm -g --defined-only so the version script only mentions symbols that are really present in the linked object. Behavior under GNU ld is unchanged (the new list is a strict subset of the previous one), and LLD now accepts the build without needing --undefined-version. Fixes #3191.
1 parent 568354c commit b0bc902

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,8 +1255,9 @@ modules: $(patsubst %.o,../rtlib/%.so,$(obj-m))
12551255
$(ECHO) Linking $@
12561256
$(Q)ld -d -r -o objects/$*.tmp $^
12571257
$(Q)objdump -w -j .rtapi_export -t objects/$*.tmp \
1258-
| awk 'BEGIN{print "{ global :"} /rtapi_exported_/{printf("%s;\n", substr($$6,16))} END{print "local : * ; };"}' \
1259-
> objects/$*.ver
1258+
| awk '/rtapi_exported_/{print substr($$NF,16)}' | sort -u > objects/$*.exported
1259+
$(Q)nm -g --defined-only objects/$*.tmp | awk '{print $$NF}' | sort -u > objects/$*.defsyms
1260+
$(Q)(echo "{ global :"; comm -12 objects/$*.exported objects/$*.defsyms | sed 's/$$/;/'; echo "local : * ; };") > objects/$*.ver
12601261
$(Q)$(CC) -shared -Bsymbolic -Wl,--version-script,objects/$*.ver -o $@ $^ -lm $(LDFLAGS)
12611262
$(Q)chmod -x $@
12621263

src/Makefile.modinc.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ $(foreach mod,$(patsubst %.o,%,$(obj-m)),\
121121
$(ECHO) Linking $@
122122
$(Q)ld -d -r -o $*.tmp $^
123123
$(Q)objdump -w -j .rtapi_export -t $*.tmp \
124-
| awk 'BEGIN{print "{ global :"} /rtapi_exported_/{printf("%s;\n", substr($$6,16))} END{print "local : * ; };"}' \
125-
> $*.ver
124+
| awk '/rtapi_exported_/{print substr($$NF,16)}' | sort -u > $*.exported
125+
$(Q)nm -g --defined-only $*.tmp | awk '{print $$NF}' | sort -u > $*.defsyms
126+
$(Q)(echo "{ global :"; comm -12 $*.exported $*.defsyms | sed 's/$$/;/'; echo "local : * ; };") > $*.ver
126127
$(Q)$(CC) -shared -Bsymbolic $(LDFLAGS) -Wl,--version-script,$*.ver -o $@ $^ -lm $(EXTRA_LDFLAGS)
127128
$(Q)chmod -x $@
128129
endif

0 commit comments

Comments
 (0)