From fe0baa443c079a535229317c02e663d5d87e82c6 Mon Sep 17 00:00:00 2001 From: Vasily Nemkov Date: Mon, 23 Mar 2026 02:53:18 +0100 Subject: [PATCH 1/2] Sanity check that there are no NULL symbols --- contrib/openssl-cmake/build_test_harness.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/contrib/openssl-cmake/build_test_harness.sh b/contrib/openssl-cmake/build_test_harness.sh index 5394681200cb..062c519f6172 100755 --- a/contrib/openssl-cmake/build_test_harness.sh +++ b/contrib/openssl-cmake/build_test_harness.sh @@ -51,6 +51,15 @@ build_target() { # (same libstdc++ members pulled into shim, handshaker, acvp) don't clash. objcopy --redefine-syms="$obj_dir/redefine.txt" --weaken "$obj_dir/combined.o" + # Sanity check: no prefixed undefined symbols should remain. + # If any do, they would silently resolve to NULL at link time (weak undef). + bad=$(nm -u "$obj_dir/combined.o" | grep "$PREFIX" || true) + if [ -n "$bad" ]; then + echo "ERROR: $name has prefixed undefined symbols that will not resolve:" >&2 + echo "$bad" >&2 + exit 1 + fi + ar rcs "$OUTDIR/lib${name}.a" "$obj_dir/combined.o" rm -rf "$obj_dir" } From 64c74a521eabb20b4f1a6670f6753bb3a0149b56 Mon Sep 17 00:00:00 2001 From: Vasily Nemkov Date: Mon, 23 Mar 2026 03:17:53 +0100 Subject: [PATCH 2/2] Less broad symbol weakening --- contrib/openssl-cmake/build_test_harness.sh | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/contrib/openssl-cmake/build_test_harness.sh b/contrib/openssl-cmake/build_test_harness.sh index 062c519f6172..c89904776380 100755 --- a/contrib/openssl-cmake/build_test_harness.sh +++ b/contrib/openssl-cmake/build_test_harness.sh @@ -42,23 +42,23 @@ build_target() { awk -v p="$PREFIX" '{print p $0 " " $0}' "$obj_dir/undef.txt" > "$obj_dir/redefine.txt" awk -v p="$PREFIX" '{print p $0 " " $0}' "$obj_dir/entry.txt" >> "$obj_dir/redefine.txt" + # Collect defined symbols — only these need weakening (to avoid + # duplicate-definition errors when multiple archives pull the same + # libstdc++ members). Undefined symbols must stay strong so the + # linker errors out if they cannot be resolved, instead of silently + # binding them to NULL. + # Names are prefixed to match post-pass-1 state. + nm --defined-only "$obj_dir/combined.o" | awk -v p="$PREFIX" \ + 'NF>=3{print p $NF}' | sort -u > "$obj_dir/weaken.txt" + # Two passes: objcopy applies --redefine-syms BEFORE --prefix-symbols # in a single invocation, so we must split them. # Pass 1: prefix every symbol. objcopy --prefix-symbols="$PREFIX" "$obj_dir/combined.o" # Pass 2: restore undefined refs + entry point to original names, - # and weaken all defined symbols so duplicates across archives - # (same libstdc++ members pulled into shim, handshaker, acvp) don't clash. - objcopy --redefine-syms="$obj_dir/redefine.txt" --weaken "$obj_dir/combined.o" - - # Sanity check: no prefixed undefined symbols should remain. - # If any do, they would silently resolve to NULL at link time (weak undef). - bad=$(nm -u "$obj_dir/combined.o" | grep "$PREFIX" || true) - if [ -n "$bad" ]; then - echo "ERROR: $name has prefixed undefined symbols that will not resolve:" >&2 - echo "$bad" >&2 - exit 1 - fi + # and weaken only defined symbols. + objcopy --redefine-syms="$obj_dir/redefine.txt" \ + --weaken-symbols="$obj_dir/weaken.txt" "$obj_dir/combined.o" ar rcs "$OUTDIR/lib${name}.a" "$obj_dir/combined.o" rm -rf "$obj_dir"