Skip to content

[fix](be) Fix ARM64 correctness, alignment UB, and build compatibility - #66857

Open
u70b3 wants to merge 6 commits into
apache:masterfrom
u70b3:arm-risk-hardening
Open

[fix](be) Fix ARM64 correctness, alignment UB, and build compatibility#66857
u70b3 wants to merge 6 commits into
apache:masterfrom
u70b3:arm-risk-hardening

Conversation

@u70b3

@u70b3 u70b3 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Problem Summary:

Systematic analysis of the BE codebase for aarch64 (ARM64) hazards — x86-only code paths, misaligned-access UB, and weak-memory-model races — done on a 128-core ARM server (aarch64, Ubuntu 22.04). Several real bugs were found and reproduced, plus a class of latent UB that is fragile on ARM. This PR fixes the real bugs, hardens the latent ones with zero-cost changes, and adds regression tests. A final commit fixes what prevents master from compiling at all on a current aarch64 toolchain.

Real bugs (reproduced on aarch64):

  1. common/signal_handler.h — the crash-handler election CAS is non-atomic on aarch64. The fallback chain requires HAVE___SYNC_VAL_COMPARE_AND_SWAP (never defined by this CMake build) or x86 inline asm, so aarch64 lands in a naive read-check-write that "has a race condition" (per its own comment). FailureSignalHandler() uses it to elect the single thread that dumps crash state. Reproduced with a 128-thread gtest: 2–13 threads won the election per run (should be exactly 1), which means concurrent crashers corrupt each other's dumps or crash again inside the handler. Fixed with __atomic_compare_exchange_n (available on every supported arch).
  2. service/doris_main.cpp — AArch32 asm in the startup NEON check. vadd.i32 q8,q8,q8 does not assemble on AArch64 once __ARM_NEON__ is defined (Clang defines it on some ARM targets); reproduced: unknown mnemonic 'vadd.i32'. Now picks add v8.4s,... on __aarch64__ and keeps the AArch32 spelling on __arm__.
  3. util/bfd_parser.cpp — hardcoded bfd_set_default_target("elf64-x86-64") fails on aarch64 (verified: the x86 backend is not bundled in aarch64 libbfd), logging a spurious error at every BE start. Selects the target per architecture.
  4. core/column/columns_common.cpp — the SIMD path of count_bytes_in_filter was silently compiled out on aarch64. The guard #if defined(__SSE2__) || defined(__aarch64__) && defined(__POPCNT__) already parses as __SSE2__ || (__aarch64__ && __POPCNT__) (&& binds tighter), and ARM toolchains never define __POPCNT__ (sse2neon does not define __SSE2__ either), so aarch64 always took the scalar loop. Dropped the __POPCNT__ gate so the block is enabled unconditionally on __aarch64__ (same SSE2 intrinsics via sse2neon; results verified bit-identical by ColumnsCommonTest).
  5. thirdparty/build-thirdparty.sh[[ "${USE_AVX2}" -eq 0 ]] is true for USE_AVX2=ON (bash arithmetic evaluates "ON" to 0), silently disabling croaring AVX2 for users following the script's own help text. Now normalized case-insensitively: 0/OFF/FALSE/NO disable, 1/ON/TRUE/YES or empty/unset keep enabled (consistent with the CMake boolean semantics BE sees via -DUSE_AVX2=...), unknown values warn and keep the default.

Misaligned-access UB hardening (aarch64 scalar loads tolerate misalignment so nothing crashes today, but these are C++ UB, trip UBSan, and can miscompile under aggressive optimization; unaligned_load/memcpy compile to the same single load instruction — zero cost):
util/bit_packing.inline.h (parquet/RLE decode hot path), util/bitmap_intersect.h (serialize/deserialize), storage/types.h (get_cpp_type_value on packed rows), util/hash_util.hpp (crc_hash/crc_hash64/murmur_hash2_64), ngram_bloom_filter.cpp (init — also fixes a rounded-up tail over-read: it copied words * sizeof(uint64_t) bytes from a size-byte buffer, i.e. up to 7 bytes past the end for bf sizes not divisible by 8 such as 65535; it now copies exactly size bytes and keeps the last word's tail zeroed so contains() still matches query-side filters).

Weak-memory-model hardening (aarch64 is weakly ordered):

  • io/cache/block_file_cache_profile: the statistics counters are now a plain AtomicStatistics value member with the metrics hook registered in the constructor. The previous atomic_shared_ptr load on the hot read path was not lock-free (libstdc++ implements std::atomic<shared_ptr> with an internal lock pool; the project's libc++ fallback uses the legacy lock-table free functions), and the lazy-init publication race it guarded was unreachable — the singleton is fully constructed before instance() publishes it.
  • storage/olap_common.h VersionWithTime: update_ts is atomic and is stored before the release CAS that publishes a new version. A reader that acquire-loads version and then update_ts is therefore guaranteed a timestamp at least as new as the one stored for that version's publication; "new version + stale timestamp" cannot happen (the previous store-after-CAS order left that interleaving window open on every architecture, x86 included). The residual "old version + newer ts" combination only biases compaction toward the conservative max retention count. Covered by a deterministic multi-threaded regression test.
  • bucketed_aggregation_source_operator: relaxed load of the merge-target index (whose value is then dereferenced cross-thread) → acquire, matching the sibling use in the same file.
  • util/histogram.cpp: CAS retry loops get _mm_pause (maps to isb via sse2neon on aarch64) to avoid LL/SC contention storms on many-core ARM.

Build fixes (separate commit — master does not compile on aarch64 Ubuntu 22.04 with a current distro toolchain; needed to build/test any of the above):
clang-19 compat: -Wshadow kept non-fatal (newer clang flags namespace shadowing by protobuf-generated enums), std::powfstd::pow, std::formatfmt::format, [[maybe_unused]] for a function only used on the x86_64 unwind path, UT -Wno-deprecated-declarations (libstdc++ ≥ 12), a __res_nsearchres_nsearch forwarder in glibc-compatibility (glibc ≥ 2.34 exports it only as a non-default compat version, which breaks linking the prebuilt krb5 archive), and #define SNII_CRC32C_X86 0 on non-x86 in snii/encoding/crc32c.cpp (the BE_TEST-only TU used the macro in #if without defining it off-x86, so -Wundef -Werror broke the aarch64 doris_be_test link).

How verified (TDD on a 128-core aarch64 server)

  • The CAS race test fails before the fix (2–13 winners/128 threads) and passes after; same for the asm compile check and the bfd/bash behavior checks.
  • New unaligned-buffer tests pass with the hardening and serve as regression guards (also runnable under -fsanitize=alignment); the ngram exact-size test (bf sizes 65/67/100/511/65535, zero-slack buffers) is the ASan guard for the tail over-read.
  • VersionWithTimeTest (4 readers × 20k version publications) deterministically passes with the fixed publication order and has a real failure window under the old order.
  • SignalHandlerTest, NGramBloomFilterTest, BitPackingUnalignedTest, BitmapIntersectTest (incl. VecDateTimeValue keys), ColumnsCommonTest, HashUtilUnalignedTest (murmur + crc + crc64), VersionWithTimeTest: 16/16 pass on aarch64 (clang 19.1.7, -march=armv8-a+crc), full doris_be_test link included.
  • 251 existing unit tests across the touched areas (bit packing, bitmap, bloom filter, crc, hash util, histogram, columns): all pass.
  • Full FE+BE build with these changes succeeds (-Werror), single-node cluster smoke test (create/insert/filter/aggregate/md5) verified.

Known follow-ups (out of scope for this PR)

  • Narrow the global -Wno-error=shadow exemption: existing warnings (mostly protobuf-generated enum collisions) are numerous and deserve a scoped cleanup PR.
  • Run the new ngram exact-size test under an ASAN_UT build so the over-read guard actively trips on regression (functional semantics already verified in the normal build).
  • The bucketed_aggregation acquire load and histogram _mm_pause have no dedicated tests — memory-ordering and spin-hint behavior are not practically unit-testable; the comments there are the guard.
  • This PR spans several independent fault domains (ARM64 correctness / alignment UB / concurrency / build / croaring config); happy to split it into per-theme PRs if reviewers prefer that for review and backport.

Release note

Fix several aarch64 (ARM64) correctness and build issues in BE, including a non-atomic CAS in the crash signal handler, and harden hot paths against misaligned-access UB and weak-memory-ordering hazards.

Check List (For Author)

  • Test

    • Unit Test
    • Manual test (add detailed scripts or steps below)
      • Built FE+BE on aarch64 Ubuntu 22.04 (clang 19.1.7, -march=armv8-a+crc), started a single-node cluster, ran create/insert/select smoke SQL successfully. Unit tests: run-be-ut.sh --run --filter='SignalHandlerTest.*:NGramBloomFilterTest.*:BitPackingUnalignedTest.*:BitmapIntersectTest.*:ColumnsCommonTest.*:HashUtilUnalignedTest.*:VersionWithTimeTest.*' (16/16 pass).
  • Behavior changed:

    • Yes. No on-disk format, protocol, or hash-output change (the hardening only changes how the same bytes are loaded, and bloom-filter bits are byte-identical). Runtime behavior changes: the crash-handler election is now atomic on aarch64 (exactly one dumper), the aarch64 SIMD popcount path in count_bytes_in_filter is enabled (same results, faster), the bfd default target is selected per architecture (spurious BE-start error log on aarch64 is gone), and croaring now honors the documented USE_AVX2 switch consistently with BE's CMake.
  • Does this need documentation?

    • No.

@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@u70b3
u70b3 force-pushed the arm-risk-hardening branch from a7a87ab to f55f0c8 Compare August 18, 2026 01:46
@u70b3
u70b3 marked this pull request as draft August 18, 2026 01:47
@u70b3 u70b3 changed the title [fix](be) Fix and harden aarch64 (ARM64) risk code paths [fix](be) Fix ARM64 correctness, alignment UB, and build compatibility Aug 18, 2026
@u70b3
u70b3 marked this pull request as ready for review August 18, 2026 06:45
@u70b3
u70b3 force-pushed the arm-risk-hardening branch 4 times, most recently from 49c43f0 to 80432a7 Compare August 21, 2026 12:13
u70b3 added a commit to u70b3/doris that referenced this pull request Aug 21, 2026
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66857

Problem Summary: The ARM hardening changes used Bash 4 lowercase expansion in the third-party build, which breaks the Bash 3.2 shipped by supported macOS runners. The bit-packing alignment fix also left the whole unpack function excluded from undefined-behavior sanitization, so the new alignment regression test could not detect a reintroduced misaligned dereference. Use Bash 3-compatible case patterns and restore UBSan instrumentation now that all word reads use memcpy-based unaligned_load.

### Release note

None

### Check List (For Author)

- Test: Unit Test / Manual test
    - Bash syntax and extracted boolean case matrix
    - BE build hygiene and diff checks
    - Clang 19 alignment-sanitized BitPackingUnalignedTest (1/1 passed)
- Behavior changed: No (restores supported build compatibility and sanitizer coverage)
- Does this need documentation: No
u70b3 added a commit to u70b3/doris that referenced this pull request Aug 27, 2026
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66857

Problem Summary: The ARM hardening changes used Bash 4 lowercase expansion in the third-party build, which breaks the Bash 3.2 shipped by supported macOS runners. The bit-packing alignment fix also left the whole unpack function excluded from undefined-behavior sanitization, so the new alignment regression test could not detect a reintroduced misaligned dereference. Use Bash 3-compatible case patterns and restore UBSan instrumentation now that all word reads use memcpy-based unaligned_load.

### Release note

None

### Check List (For Author)

- Test: Unit Test / Manual test
    - Bash syntax and extracted boolean case matrix
    - BE build hygiene and diff checks
    - Clang 19 alignment-sanitized BitPackingUnalignedTest (1/1 passed)
- Behavior changed: No (restores supported build compatibility and sanitizer coverage)
- Does this need documentation: No
@u70b3
u70b3 force-pushed the arm-risk-hardening branch from 39280bd to 62880e9 Compare August 27, 2026 08:00
@u70b3

u70b3 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@u70b3

u70b3 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

/review

@u70b3

u70b3 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Hi @gavinchou @yiguolei @Gabriel39 @morningman — gentle ping for review when you have a moment. This PR fixes several aarch64 (ARM64) correctness bugs reproduced on real ARM hardware (128-core server): a non-atomic CAS in the crash-handler election, AArch32 asm in the startup NEON check, a hardcoded x86-64 bfd target, and a SIMD popcount path silently compiled out on aarch64. It also adds zero-cost alignment-UB / memory-ordering hardening and the build fixes needed to compile master on a current aarch64 toolchain. Every fix carries a regression test, and buildall CI is running now.

The PR spans a few independent fault domains — I'm happy to split it into per-theme PRs if that makes review and backporting easier. Thanks!

@u70b3

u70b3 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

Backport analysis for reviewers/committers: these bugs exist on all active release lines, but branch-4.0 and earlier still use the old be/src/vec + be/src/olap layout, so an automatic cherry-pick of the whole PR would conflict heavily there. branch-4.1 shares master's layout — a pick should apply almost cleanly except be/src/storage/index/snii/encoding/crc32c.cpp and be/src/exec/operator/bucketed_aggregation_source_operator.cpp, which don't exist on 4.1 (those two hunks can simply be dropped during the pick).

Could a committer please add the dev/4.1.x label? (I don't have triage permission.) If aarch64 fixes are still wanted on 4.0/3.1, I'd prefer to file a separate trimmed manual backport PR covering just signal_handler / doris_main / bfd / thirdparty / build fixes rather than auto-picking this whole PR.

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 17022 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit 62880e9d827fbd4d0ed2985483738d8fa61ca330, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17585	3054	3016	3016
q2	2129	281	238	238
q3	10178	943	531	531
q4	4671	255	205	205
q5	7668	578	391	391
q6	136	135	95	95
q7	546	513	392	392
q8	9254	946	927	927
q9	3510	2419	2474	2419
q10	6516	900	737	737
q11	405	205	182	182
q12	625	267	204	204
q13	18126	1540	1185	1185
q14	157	157	150	150
q15	q16	441	403	375	375
q17	1422	841	793	793
q18	3114	2354	2292	2292
q19	1273	939	740	740
q20	389	295	210	210
q21	5620	1704	1929	1704
q22	322	278	236	236
Total cold run time: 94087 ms
Total hot run time: 17022 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3418	3349	3339	3339
q2	511	394	390	390
q3	2340	2325	2280	2280
q4	1215	1197	919	919
q5	2237	2189	2173	2173
q6	176	114	88	88
q7	1089	988	962	962
q8	1649	1453	1450	1450
q9	3221	3204	3174	3174
q10	1882	1857	1626	1626
q11	374	284	261	261
q12	464	443	353	353
q13	1506	1541	1195	1195
q14	178	188	159	159
q15	q16	409	404	371	371
q17	3735	3377	3360	3360
q18	4944	4532	5109	4532
q19	953	873	857	857
q20	1049	976	816	816
q21	3984	3296	3270	3270
q22	407	356	322	322
Total cold run time: 35741 ms
Total hot run time: 31897 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 84013 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit 62880e9d827fbd4d0ed2985483738d8fa61ca330, data reload: false

query5	4280	435	364	364
query6	407	141	126	126
query7	4874	417	239	239
query8	293	146	119	119
query9	8686	3039	3046	3039
query10	416	228	192	192
query11	5399	1068	943	943
query12	124	74	73	73
query13	1213	444	325	325
query14	6062	2236	2155	2155
query14_1	2046	2020	2033	2020
query15	173	125	123	123
query16	934	356	373	356
query17	824	471	383	383
query18	2333	346	253	253
query19	175	152	122	122
query20	75	73	74	73
query21	208	113	91	91
query22	5556	5402	5443	5402
query23	6885	6366	6033	6033
query23_1	6338	6200	6177	6177
query24	7336	1115	805	805
query24_1	787	778	784	778
query25	455	318	269	269
query26	1223	234	132	132
query27	2779	427	262	262
query28	4682	1513	1517	1513
query29	978	472	363	363
query30	250	159	144	144
query31	841	414	350	350
query32	127	83	91	83
query33	479	228	189	189
query34	1021	836	494	494
query35	414	406	356	356
query36	581	568	546	546
query37	121	85	79	79
query38	1028	864	839	839
query39	529	497	488	488
query39_1	492	504	499	499
query40	203	96	82	82
query41	63	57	60	57
query42	81	75	76	75
query43	243	244	219	219
query44	1035	579	568	568
query45	109	106	103	103
query46	763	832	558	558
query47	766	768	714	714
query48	319	301	221	221
query49	533	247	197	197
query50	714	270	201	201
query51	8148	8257	8209	8209
query52	67	70	69	69
query53	198	190	158	158
query54	317	193	177	177
query55	74	60	57	57
query56	209	174	172	172
query57	683	702	654	654
query58	204	189	174	174
query59	1229	1248	1106	1106
query60	262	197	183	183
query61	144	149	149	149
query62	369	207	186	186
query63	178	148	139	139
query64	2766	730	610	610
query65	1671	1597	1647	1597
query66	1799	270	215	215
query67	9860	9733	9879	9733
query68	3023	1281	753	753
query69	352	228	216	216
query70	682	615	619	615
query71	250	182	171	171
query72	2411	1818	1648	1648
query73	676	600	335	335
query74	2018	1238	1163	1163
query75	1221	1108	970	970
query76	2353	743	548	548
query77	256	280	212	212
query78	3954	3786	3379	3379
query79	2191	883	614	614
query80	1592	334	279	279
query81	488	163	134	134
query82	637	124	97	97
query83	284	219	199	199
query84	295	115	87	87
query85	817	363	308	308
query86	397	191	178	178
query87	1039	993	917	917
query88	2819	2154	2138	2138
query89	297	206	183	183
query90	1968	139	141	139
query91	134	125	103	103
query92	89	75	67	67
query93	1461	1090	738	738
query94	655	305	239	239
query95	544	329	240	240
query96	772	555	257	257
query97	1088	1074	1051	1051
query98	150	144	136	136
query99	428	350	320	320
Total cold run time: 179200 ms
Total hot run time: 84013 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 14.91 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit 62880e9d827fbd4d0ed2985483738d8fa61ca330, data reload: false

query1	0.01	0.00	0.01
query2	0.08	0.04	0.04
query3	0.24	0.11	0.11
query4	1.60	0.10	0.09
query5	0.18	0.16	0.16
query6	1.23	0.74	0.70
query7	0.04	0.01	0.00
query8	0.05	0.03	0.04
query9	0.30	0.22	0.22
query10	0.34	0.34	0.35
query11	0.17	0.11	0.12
query12	0.14	0.12	0.13
query13	0.33	0.32	0.32
query14	0.45	0.46	0.46
query15	0.37	0.36	0.36
query16	0.21	0.24	0.26
query17	0.73	0.69	0.75
query18	0.19	0.16	0.18
query19	1.23	1.24	1.17
query20	0.01	0.01	0.01
query21	15.44	0.15	0.11
query22	5.07	0.04	0.04
query23	16.15	0.26	0.11
query24	3.00	0.34	0.25
query25	0.10	0.05	0.03
query26	0.75	0.17	0.13
query27	0.04	0.03	0.03
query28	3.50	0.58	0.26
query29	12.43	3.20	2.58
query30	0.25	0.11	0.13
query31	2.76	0.37	0.18
query32	3.51	0.33	0.24
query33	1.49	1.52	1.39
query34	15.42	2.20	1.81
query35	1.81	1.77	1.80
query36	0.46	0.32	0.31
query37	0.06	0.04	0.04
query38	0.06	0.03	0.03
query39	0.04	0.02	0.03
query40	0.12	0.08	0.08
query41	0.08	0.02	0.03
query42	0.03	0.03	0.02
query43	0.03	0.03	0.02
Total cold run time: 90.5 s
Total hot run time: 14.91 s

@u70b3

u70b3 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

u70b3 added 2 commits August 29, 2026 15:35
- SignalHandlerTest: 128-thread race on the CAS used by the crash-handler
  thread election. On aarch64 (where the fallback chain ends in a naive
  non-atomic read-check-write) 2-13 of 128 threads win the election;
  exactly one must win.
- NGramBloomFilter / BitPacking / BitmapIntersect / HashUtil unaligned
  tests: exercise the code paths with deliberately misaligned buffers
  (offset 1..7) so the memcpy-based hardening is regression-guarded and
  UBSan-ready.
- ColumnsCommonTest: pin the signed '>' 0 semantics of
  count_bytes_in_filter (bytes 128..255 must not be counted) so the
  scalar and SIMD paths always agree.
Real bugs:
- common/signal_handler.h: the CAS used to elect the single crash-dumping
  thread fell back to a non-atomic read-check-write on aarch64
  (HAVE___SYNC_VAL_COMPARE_AND_SWAP is never defined by this CMake build
  and the inline-asm branch is x86-only). On a 128-core ARM server,
  2-13 of 128 racing threads won the election, corrupting crash dumps.
  Use __atomic_compare_exchange_n which exists on all supported arches.
- service/doris_main.cpp: the startup NEON self-check used AArch32 asm
  (vadd.i32 q8,...) which no aarch64 assembler accepts once __ARM_NEON__
  is defined (Clang targets); pick the spelling per architecture.
- util/bfd_parser.cpp: bfd_set_default_target hardcoded elf64-x86-64,
  which fails on aarch64 (the x86 backend is not bundled there) and
  logged a spurious error on every BE start; select per-arch target.
- core/column/columns_common.cpp: '|| &&' precedence typo silently
  compiled out the SIMD path of count_bytes_in_filter on aarch64.
- thirdparty/build-thirdparty.sh: [[ USE_AVX2 -eq 0 ]] is true for 'ON'
  (bash arithmetic), silently disabling croaring AVX2 for users who
  export USE_AVX2=ON; use a string compare.

Misaligned-access UB hardening (zero-cost unaligned_load/memcpy; aarch64
scalar loads tolerate misalignment but the casts are UB and break UBSan):
- util/bit_packing.inline.h UnpackValue (parquet/RLE decode hot path)
- util/bitmap_intersect.h serialize/deserialize helpers
- storage/types.h BaseFieldTypeTraits::get_cpp_type_value (packed rows)
- util/hash_util.hpp crc_hash/crc_hash64/murmur_hash2_64
- ngram_bloom_filter.cpp init (also fixes reserve-then-index misuse)

Weak-memory-ordering hardening for aarch64:
- io/cache/block_file_cache_profile: use atomic_shared_ptr for lock-free
  stats access (DCL on a plain shared_ptr can observe a torn or
  half-constructed object)
- storage/olap_common.h VersionWithTime: atomic update_ts and
  release/acquire CAS so readers never see new version + stale ts
- bucketed_aggregation_source_operator: acquire load for the cross-thread
  merge-target index (was relying on data-dependency ordering)
- util/histogram.cpp: _mm_pause backoff in CAS retry loops
u70b3 and others added 4 commits August 29, 2026 15:35
- bitmap_value.h: suppress -Wshadow for BitmapDataType enum constants
  (they collide with protobuf-exported doris::BITMAP; clang >= 17 turns
  it into an -Werror failure)
- be/CMakeLists.txt: keep -Wshadow non-fatal on clang, and
  -Wno-deprecated-declarations for BE_TEST (libstdc++ >= 12 marks
  std::get_temporary_buffer deprecated, tripping existing tests)
- parquet_column_convert.h: std::powf -> std::pow (libstdc++ <cmath>
  does not declare powf in namespace std)
- function_string_misc.cpp: std::format -> fmt::format (libstdc++ 12
  has no <format>; fmt is the project convention)
- be_thread_stack_action.cpp: append_frame is only used on the x86_64
  unwind path; mark [[maybe_unused]] so aarch64 -Werror builds pass
- glibc-compatibility: add resolv_shim.c forwarding __res_nsearch to
  res_nsearch — glibc >= 2.34 exports the former only as a non-default
  compat version, breaking the link against the prebuilt krb5 archive
…consistency

Review round for the aarch64 hardening PR:

- olap_common.h: store update_ts BEFORE the release CAS that publishes a
  new version, so a reader can never observe "new version + stale
  timestamp" (the previous order left an interleaving window on any arch);
  document the exact invariant instead of overclaiming; add
  VersionWithTimeTest concurrency regression test.
- ngram_bloom_filter: init() copied words*8 rounded-up bytes from the
  caller buffer, over-reading up to 7 bytes for bf sizes not divisible by
  8 (e.g. 65535). Copy exactly size bytes and keep the tail zeroed so
  contains() matches query-side filters; add exact-size ASan guard test
  (65/67/100/511/65535). The old "reserve()-then-index" root-cause story
  was wrong: the constructor already sized the vector.
- block_file_cache_profile: replace the atomic_shared_ptr (not lock-free:
  libstdc++ lock pool / legacy free-function lock table) with an
  AtomicStatistics value member and register the metrics hook in the
  constructor. The lazy-init publication race it guarded was unreachable
  because the singleton is fully constructed before publication.
- build-thirdparty.sh: accept CMake boolean spellings for USE_AVX2
  (0/OFF/FALSE/NO, case-insensitive) so croaring agrees with BE's CMake
  when users set e.g. USE_AVX2=OFF; unknown values warn and keep default.
- glibc-compatibility: resolv_shim.c was compiled twice (globbed into the
  archive AND listed in the explicit OBJECT lib); REMOVE_ITEM it from the
  globbed sources.
- signal_handler.h / columns_common.cpp: fix stale and misleading comments
  (the naive CAS fallback is gone; the aarch64 SIMD guard was not
  "parenthesized" - the __POPCNT__ gate was dropped).
- tests: unaligned-buffer coverage for crc_hash and crc_hash64 (only
  murmur_hash2_64 had it); VecDateTimeValue misaligned round-trip for
  bitmap_intersect (the int32 test comment overclaimed); correct the int32
  test comment.
- snii/encoding/crc32c.cpp: define SNII_CRC32C_X86 as 0 on non-x86 so the
  BE_TEST-only TU compiles with -Wundef -Werror on aarch64. Pre-existing
  break from apache#66809 that blocked linking doris_be_test, unrelated to the
  review edits.

Verified on aarch64 (clang 19.1.7, -march=armv8-a+crc): full ninja
doris_be_test build clean; 16/16 tests pass across VersionWithTimeTest,
NGramBloomFilterTest, HashUtilUnalignedTest, BitmapIntersectTest,
SignalHandlerTest, ColumnsCommonTest, BitPackingUnalignedTest.
### What problem does this PR solve?

Issue Number: None

Related PR: apache#66857

Problem Summary: The ARM hardening changes used Bash 4 lowercase expansion in the third-party build, which breaks the Bash 3.2 shipped by supported macOS runners. The bit-packing alignment fix also left the whole unpack function excluded from undefined-behavior sanitization, so the new alignment regression test could not detect a reintroduced misaligned dereference. Use Bash 3-compatible case patterns and restore UBSan instrumentation now that all word reads use memcpy-based unaligned_load.

### Release note

None

### Check List (For Author)

- Test: Unit Test / Manual test
    - Bash syntax and extracted boolean case matrix
    - BE build hygiene and diff checks
    - Clang 19 alignment-sanitized BitPackingUnalignedTest (1/1 passed)
- Behavior changed: No (restores supported build compatibility and sanitizer coverage)
- Does this need documentation: No
…rsion

On glibc < 2.34 (e.g. the AlmaLinux 8 / glibc 2.28 CI build image),
<resolv.h> #defines res_nsearch as __res_nsearch, so the forwarder body
called itself and clang -Werror -Winfinite-recursion broke the BE UT and
COMPILE checks. The shim is only needed on glibc >= 2.34 anyway (older
glibc still exports __res_nsearch as a default-versioned symbol), so gate
it with __GLIBC_PREREQ(2, 34) and keep the translation unit non-empty for
-Wpedantic.
@u70b3
u70b3 force-pushed the arm-risk-hardening branch from 70d268f to 0204934 Compare August 29, 2026 07:35
@u70b3

u70b3 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

run buildall

@u70b3

u70b3 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

/review

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 64.00% (32/50) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 62.78% (29371/46782)
Line Coverage 47.76% (307324/643415)
Region Coverage 43.37% (248152/572158)
Branch Coverage 44.91% (115444/257054)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants