Skip to content

Commit 0212dc2

Browse files
author
colinlyguo
committed
fix script verification logic and regenerate .a files
1 parent 91f3f98 commit 0212dc2

7 files changed

+86
-67
lines changed

β€Žencoding/zstd/add_symbol_prefix.shβ€Ž

Lines changed: 86 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ echo
2222
for lib_info in "${LIBRARIES[@]}"; do
2323
IFS=':' read -r LIB_FILE PREFIX <<< "$lib_info"
2424
REDEFINE_FILE="redefine_${LIB_FILE%.*}.syms"
25-
25+
2626
echo "Processing $LIB_FILE with prefix '$PREFIX'"
2727

2828
# Check if library file exists
2929
if [ ! -f "$LIB_FILE" ]; then
3030
echo "Warning: Library file not found: $LIB_FILE, skipping..."
3131
continue
3232
fi
33-
33+
3434
# Check if library is already processed by looking for our prefix
3535
if "$LLVM_NM" "$LIB_FILE" 2>/dev/null | grep -q "${PREFIX}"; then
3636
echo "Library $LIB_FILE already processed (found ${PREFIX} symbols), skipping..."
@@ -46,9 +46,32 @@ for lib_info in "${LIBRARIES[@]}"; do
4646
}
4747
/^[0-9a-fA-F]+ [TDBS] / {
4848
if ($3 != "" && $3 !~ /^\./ && $3 !~ /^__/ && $3 !~ /^'"$PREFIX"'/) {
49+
# Original patterns
4950
if ($3 ~ /^(entropy|fse|huf|zstd|hist|error|mem_|pool|param|cover|dict)/) {
5051
print $3 " '"$PREFIX"'" $3
5152
}
53+
# Add conflict symbols found by verification logic below
54+
if ($3 == "_atomic_flag_test_and_set" ||
55+
$3 == "_atomic_signal_fence" ||
56+
$3 == "_divbwt" ||
57+
$3 == "divsufsort" ||
58+
$3 == "g_debuglevel" ||
59+
$3 == "rust_begin_unwind" ||
60+
$3 == "init_cpu_features" ||
61+
$3 == "_ERR_getErrorString" ||
62+
$3 == "_atomic_flag_clear" ||
63+
$3 == "_atomic_flag_clear_explicit" ||
64+
$3 == "_atomic_flag_test_and_set_explicit" ||
65+
$3 == "_atomic_thread_fence" ||
66+
$3 == "_divsufsort" ||
67+
$3 == "_g_debuglevel" ||
68+
$3 == "rust_eh_personality" ||
69+
$3 == "divbwt" ||
70+
$3 == "rust_panic" ||
71+
$3 == "ERR_getErrorString" ||
72+
$3 == "init_cpu_features_resolver") {
73+
print $3 " '"$PREFIX"'" $3
74+
}
5275
}
5376
}
5477
' | sort | uniq > "$REDEFINE_FILE"
@@ -111,85 +134,81 @@ for LIB_FILE in "${LIB_FILES[@]}"; do
111134
' >> "$temp_file"
112135
done
113136

137+
echo "1. Checking for duplicate symbols across libraries (by architecture):"
138+
echo " (Only checking within same architecture - cross-architecture conflicts are expected and ignored)"
114139
echo
115-
echo "1. Checking for duplicate symbols across libraries:"
116-
117-
# Find conflicting symbols
118-
conflicts_output=$(awk '{symbols[$1] = symbols[$1] "\n" $2} END {
119-
conflicts = 0
120-
for (sym in symbols) {
121-
count = gsub(/\n/, "&", symbols[sym])
122-
if (count > 1) {
123-
conflicts++
124-
if (conflicts <= 10) { # Show first 10 conflicts
125-
print " ❌ CONFLICT: " sym
126-
libs = symbols[sym]
127-
gsub(/\n/, ", ", libs)
128-
print " Found in: " libs
129-
print ""
130-
}
131-
}
132-
}
133-
if (conflicts == 0) {
134-
print " βœ… No symbol conflicts found!"
135-
return 0
136-
} else {
137-
print " ❌ Found " conflicts " conflicting symbols" (conflicts > 10 ? " (showing first 10)" : "")
138-
return conflicts
139-
}
140-
}' "$temp_file")
141-
142-
echo "$conflicts_output"
143-
conflict_count=$(echo "$conflicts_output" | tail -1 | grep -o '[0-9]\+' | tail -1 || echo 0)
144140

145-
echo
146-
echo "2. Prefix application verification:"
141+
# Define architectures
142+
architectures=("darwin_arm64" "linux_amd64" "linux_arm64")
147143

148-
for lib_info in "${LIBRARIES[@]}"; do
149-
IFS=':' read -r LIB_FILE PREFIX <<< "$lib_info"
144+
total_conflicts=0
145+
for arch in "${architectures[@]}"; do
146+
echo " Architecture: $arch"
147+
148+
# Create temp file for this architecture
149+
arch_temp_file=$(mktemp)
150+
151+
# Collect symbols for this architecture only
152+
for lib_info in "${LIBRARIES[@]}"; do
153+
IFS=':' read -r LIB_FILE PREFIX <<< "$lib_info"
150154

151-
if [ ! -f "$LIB_FILE" ]; then
152-
continue
153-
fi
155+
# Skip if file doesn't exist or doesn't match current architecture
156+
if [ ! -f "$LIB_FILE" ] || [[ "$LIB_FILE" != *"$arch"* ]]; then
157+
continue
158+
fi
154159

155-
# Count unprefixed target symbols
156-
unprefixed_targets=$("$LLVM_NM" "$LIB_FILE" 2>/dev/null | awk -v prefix="$PREFIX" '
157-
/^[0-9a-fA-F]+ [TDBS] / {
158-
if ($3 != "" && $3 !~ /^\./ && $3 !~ /^__/ && $3 !~ ("^" prefix)) {
159-
# Check if it matches our target patterns
160-
if ($0 ~ /ZSTD|HUF|FSE|ZBUFF|HIST|ERROR|MEM_|XXH|COVER|DICT|POOL|PARAM/ ||
161-
$3 ~ /^(entropy|fse|huf|zstd|hist|error|mem_|pool|param|cover|dict)/) {
162-
print $3
160+
"$LLVM_NM" "$LIB_FILE" 2>/dev/null | awk -v lib="$LIB_FILE" '
161+
/^[0-9a-fA-F]+ [TDBS] / {
162+
if ($3 != "" && $3 !~ /^\./ && $3 !~ /^__/ && $3 !~ /^_ZN/) {
163+
print $3 "\t" lib
163164
}
164-
}
165-
}' | wc -l)
166-
167-
# Count prefixed symbols
168-
prefixed_count=$("$LLVM_NM" "$LIB_FILE" 2>/dev/null | grep -c "${PREFIX}" || echo 0)
169-
170-
echo " $LIB_FILE:"
171-
echo " - Prefixed symbols (${PREFIX}*): $prefixed_count"
172-
echo " - Unprefixed target symbols: $unprefixed_targets"
165+
}' >> "$arch_temp_file"
166+
done
173167

174-
if [ "$unprefixed_targets" -gt 0 ]; then
175-
echo " ⚠️ Still has $unprefixed_targets unprefixed target symbols"
176-
echo " Examples:"
177-
"$LLVM_NM" "$LIB_FILE" 2>/dev/null | awk -v prefix="$PREFIX" '
178-
/^[0-9a-fA-F]+ [TDBS] / {
179-
if ($3 != "" && $3 !~ /^\./ && $3 !~ /^__/ && $3 !~ ("^" prefix)) {
180-
if ($0 ~ /ZSTD|HUF|FSE|ZBUFF|HIST|ERROR|MEM_|XXH|COVER|DICT|POOL|PARAM/ ||
181-
$3 ~ /^(entropy|fse|huf|zstd|hist|error|mem_|pool|param|cover|dict)/) {
182-
print " " $3
168+
# Check for conflicts within this architecture
169+
if [ -s "$arch_temp_file" ]; then
170+
arch_conflicts=$(awk '{symbols[$1] = symbols[$1] "\n" $2} END {
171+
conflicts = 0
172+
conflict_list = ""
173+
for (sym in symbols) {
174+
count = gsub(/\n/, "&", symbols[sym])
175+
if (count > 1) {
176+
conflicts++
177+
print " ❌ CONFLICT: " sym
178+
libs = symbols[sym]
179+
gsub(/\n/, ", ", libs)
180+
print " Found in: " libs
183181
}
184182
}
185-
}' | head -3
183+
if (conflicts == 0) {
184+
print " βœ… No symbol conflicts found within this architecture!"
185+
} else {
186+
print " ❌ Found " conflicts " conflicting symbols (all shown above)"
187+
}
188+
print "CONFLICT_COUNT:" conflicts
189+
}' "$arch_temp_file")
190+
191+
echo "$arch_conflicts"
192+
arch_conflict_count=$(echo "$arch_conflicts" | grep "CONFLICT_COUNT:" | cut -d: -f2 || echo 0)
193+
total_conflicts=$((total_conflicts + arch_conflict_count))
186194
else
187-
echo " βœ… All target symbols properly prefixed"
195+
echo " βœ… No libraries found for this architecture"
188196
fi
197+
198+
rm "$arch_temp_file"
189199
echo
190200
done
191201

192-
echo "3. Sample prefixed symbols from each library:"
202+
# Summary
203+
if [ "$total_conflicts" -eq 0 ]; then
204+
echo "πŸŽ‰ All architectures passed symbol conflict check!"
205+
else
206+
echo "⚠️ Found $total_conflicts total symbol conflicts across all architectures"
207+
fi
208+
209+
conflict_count=$total_conflicts
210+
211+
echo "2. Sample prefixed symbols from each library:"
193212
for lib_info in "${LIBRARIES[@]}"; do
194213
IFS=':' read -r LIB_FILE PREFIX <<< "$lib_info"
195214

384 Bytes
Binary file not shown.
698 Bytes
Binary file not shown.
758 Bytes
Binary file not shown.
448 Bytes
Binary file not shown.
768 Bytes
Binary file not shown.
840 Bytes
Binary file not shown.

0 commit comments

Comments
Β (0)