Skip to content

[fix](build) Let ScopedLSANDisabler compile without a sanitizer#66049

Open
airborne12 wants to merge 1 commit into
apache:masterfrom
airborne12:fix-lsan-disabler-without-sanitizer
Open

[fix](build) Let ScopedLSANDisabler compile without a sanitizer#66049
airborne12 wants to merge 1 commit into
apache:masterfrom
airborne12:fix-lsan-disabler-without-sanitizer

Conversation

@airborne12

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

doris_be_test can only be linked as an ASAN build. BUILD_TYPE_UT=DEBUG and BUILD_TYPE_UT=RELEASE
both fail at link:

ld.lld: error: undefined symbol: __lsan_disable
>>> referenced by leak_annotations.h:84
>>>               cached_remote_file_reader_peer_test.cpp.o:(doris::debug::ScopedLSANDisabler::ScopedLSANDisabler())

be/src/util/debug/leak_annotations.h computes DORIS_LSAN_ENABLED and uses it to guard
ANNOTATE_LEAKING_OBJECT_PTR, but ScopedLSANDisabler sits outside every #if:

class ScopedLSANDisabler {
public:
    ScopedLSANDisabler()  { __lsan_disable(); }
    ~ScopedLSANDisabler() { __lsan_enable();  }
};

__lsan_disable / __lsan_enable are only declared in that header; they are defined by the
LeakSanitizer runtime. Without -fsanitize=address (or =leak) nothing provides them, so every
translation unit that instantiates the class emits an undefined reference. Two do —
be/src/util/debug/leakcheck_disabler.h and be/test/io/cache/cached_remote_file_reader_peer_test.cpp.

This matters beyond tidiness: it means there is no way to produce an optimized, un-instrumented unit
test binary, so unit tests cannot be used for any timing work — ASAN's allocator instrumentation and
-O0 dominate whatever is being measured.

The guard is extended to cover the class. With no LeakSanitizer there is nothing to suppress, so it
degrades to a no-op, which is the same reasoning ANNOTATE_LEAKING_OBJECT_PTR already applies.

Release note

None

Check List (For Author)

  • Test

    • Regression test

    • Unit Test

    • Manual test (add detailed scripts or steps below)

      Compiled a translation unit that instantiates ScopedLSANDisabler both ways and inspected the
      undefined symbols, which isolates the change from everything else in the binary:

      # master header, no sanitizer -> the undefined references that break the link
      $ nm -u probe_orig.o | grep lsan
                       U __lsan_disable
                       U __lsan_enable
      
      # this PR, no sanitizer -> none
      $ nm -u probe_fixed.o | grep lsan     # (no output)
      
      # this PR, -fsanitize=address -> still emitted, suppression behaviour unchanged
      $ nm -u probe_asan.o | grep lsan
                       U __lsan_disable
                       U __lsan_enable
      

      Then built the unit test binary with BUILD_TYPE_UT=RELEASE sh run-be-ut.sh. On master it
      fails with the undefined __lsan_disable; with this change all translation units compile and
      the -O3 -DNDEBUG binary links.

      Note the no-op constructor is written out rather than = default: a defaulted constructor
      makes the type trivial, and the RELEASE build then fails with
      error: unused variable 'lsan_disabler' [-Werror,-Wunused-variable] at the two use sites.

    • No need to test or manual test. Explain why:

      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.

    • Yes.

      Under a sanitizer build nothing changes — the calls are still emitted. Without a sanitizer the
      scope guard becomes a no-op instead of failing to link, which is the only behaviour it can
      meaningfully have when there is no LeakSanitizer runtime to talk to.

  • Does this need documentation?

    • No.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

leak_annotations.h computes DORIS_LSAN_ENABLED and guards ANNOTATE_LEAKING_OBJECT_PTR with it, but
ScopedLSANDisabler sits outside every #if and calls __lsan_disable() / __lsan_enable()
unconditionally. Those are only declared in this header; the LeakSanitizer runtime defines them. So
without -fsanitize=address every translation unit that instantiates the class emitted an undefined
reference:

    ld.lld: error: undefined symbol: __lsan_disable
    >>> referenced by leak_annotations.h:84
    >>>               cached_remote_file_reader_peer_test.cpp.o

Two instantiate it -- leakcheck_disabler.h and cached_remote_file_reader_peer_test.cpp -- so
doris_be_test could only ever be linked as an ASAN build. BUILD_TYPE_UT=DEBUG and =RELEASE both
failed at link, which also means there was no way to get an optimized un-instrumented test binary,
and unit tests could not be used for any timing work.

The guard now covers the class. With no LeakSanitizer there is nothing to suppress, so it becomes a
no-op, matching what ANNOTATE_LEAKING_OBJECT_PTR already does. The no-op constructor is written out
rather than defaulted on purpose: `= default` makes the type trivial and every
`ScopedLSANDisabler guard;` then trips -Werror,-Wunused-variable.
@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?

@airborne12

Copy link
Copy Markdown
Member Author

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17809	4217	4063	4063
q2	2069	323	203	203
q3	10265	1387	824	824
q4	4681	476	340	340
q5	7512	863	595	595
q6	179	170	139	139
q7	746	841	613	613
q8	9363	1563	1590	1563
q9	5574	4295	4307	4295
q10	6803	1728	1465	1465
q11	520	349	328	328
q12	741	573	464	464
q13	18150	3523	2760	2760
q14	271	268	246	246
q15	q16	795	782	704	704
q17	1023	1053	1000	1000
q18	6777	5596	5368	5368
q19	1329	1206	1112	1112
q20	844	667	586	586
q21	5884	2687	2486	2486
q22	423	348	293	293
Total cold run time: 101758 ms
Total hot run time: 29447 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4420	4286	4328	4286
q2	300	317	213	213
q3	4568	4910	4444	4444
q4	2044	2176	1341	1341
q5	4346	4262	4268	4262
q6	227	177	126	126
q7	1719	1635	2046	1635
q8	2624	2164	2201	2164
q9	7951	8191	7736	7736
q10	4675	4597	4173	4173
q11	592	421	380	380
q12	743	756	545	545
q13	3349	3655	2915	2915
q14	321	315	282	282
q15	q16	714	734	624	624
q17	1356	1314	1359	1314
q18	8094	7385	7226	7226
q19	1148	1140	1120	1120
q20	2207	2204	1924	1924
q21	5193	4498	4406	4406
q22	519	475	398	398
Total cold run time: 57110 ms
Total hot run time: 51514 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 178215 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 44bb478b22b9b8782ecaf4ab052ebd3b83ccfa07, data reload: false

query5	4348	643	481	481
query6	471	254	230	230
query7	4901	619	351	351
query8	345	189	171	171
query9	8801	4160	4117	4117
query10	491	352	332	332
query11	5915	2336	2111	2111
query12	166	102	103	102
query13	1247	644	447	447
query14	6266	5214	4923	4923
query14_1	4241	4244	4217	4217
query15	221	205	174	174
query16	990	471	414	414
query17	948	721	578	578
query18	2444	473	355	355
query19	218	204	153	153
query20	116	109	108	108
query21	236	167	140	140
query22	13568	13542	13316	13316
query23	17208	16491	16129	16129
query23_1	16162	16151	16225	16151
query24	7432	1749	1252	1252
query24_1	1300	1292	1300	1292
query25	570	466	390	390
query26	1359	370	219	219
query27	2634	590	377	377
query28	4474	2011	1992	1992
query29	1063	653	487	487
query30	340	273	234	234
query31	1120	1098	992	992
query32	110	69	63	63
query33	552	319	260	260
query34	1184	1113	627	627
query35	761	776	674	674
query36	1176	1173	1013	1013
query37	157	104	93	93
query38	1882	1697	1683	1683
query39	899	871	874	871
query39_1	830	838	846	838
query40	248	162	144	144
query41	64	64	64	64
query42	94	90	95	90
query43	324	330	276	276
query44	1412	756	739	739
query45	196	197	168	168
query46	1072	1177	722	722
query47	2123	2131	2061	2061
query48	410	399	309	309
query49	575	406	307	307
query50	1078	415	341	341
query51	10797	10697	10841	10697
query52	84	87	74	74
query53	269	277	203	203
query54	272	240	222	222
query55	78	71	64	64
query56	289	306	299	299
query57	1318	1279	1208	1208
query58	277	244	244	244
query59	1590	1686	1440	1440
query60	298	267	254	254
query61	174	175	151	151
query62	559	497	435	435
query63	240	203	196	196
query64	2841	1033	903	903
query65	4696	4629	4616	4616
query66	1828	507	383	383
query67	29353	29109	29095	29095
query68	3347	1523	968	968
query69	437	300	258	258
query70	1043	939	935	935
query71	371	319	316	316
query72	2997	2665	2352	2352
query73	835	797	432	432
query74	5075	4926	4730	4730
query75	2531	2483	2130	2130
query76	2310	1177	729	729
query77	351	371	286	286
query78	11774	11924	11369	11369
query79	1400	1193	776	776
query80	650	561	477	477
query81	470	333	301	301
query82	554	154	122	122
query83	399	322	305	305
query84	327	157	129	129
query85	939	604	507	507
query86	360	300	281	281
query87	1888	1810	1749	1749
query88	3753	2760	2745	2745
query89	443	382	333	333
query90	1995	194	194	194
query91	196	190	159	159
query92	64	57	55	55
query93	1526	1599	935	935
query94	529	344	315	315
query95	790	593	478	478
query96	1128	849	358	358
query97	2583	2626	2464	2464
query98	211	203	199	199
query99	1094	1102	968	968
Total cold run time: 262497 ms
Total hot run time: 178215 ms

@hello-stephen

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

query1	0.01	0.00	0.01
query2	0.14	0.05	0.05
query3	0.25	0.13	0.14
query4	1.60	0.14	0.14
query5	0.24	0.24	0.22
query6	1.26	1.09	1.02
query7	0.05	0.01	0.00
query8	0.06	0.04	0.04
query9	0.38	0.32	0.31
query10	0.56	0.54	0.57
query11	0.19	0.13	0.13
query12	0.17	0.14	0.14
query13	0.46	0.46	0.48
query14	1.03	1.01	1.00
query15	0.64	0.59	0.59
query16	0.31	0.32	0.32
query17	1.07	1.12	1.10
query18	0.21	0.20	0.21
query19	2.04	1.94	1.95
query20	0.02	0.02	0.01
query21	15.43	0.23	0.14
query22	4.85	0.06	0.05
query23	16.16	0.29	0.13
query24	2.98	0.44	0.31
query25	0.10	0.06	0.04
query26	0.73	0.20	0.16
query27	0.04	0.03	0.03
query28	3.53	0.90	0.55
query29	12.46	4.05	3.28
query30	0.29	0.16	0.15
query31	2.77	0.57	0.31
query32	3.22	0.59	0.49
query33	3.21	3.13	3.29
query34	15.51	4.18	3.50
query35	3.50	3.51	3.48
query36	0.55	0.42	0.43
query37	0.10	0.06	0.06
query38	0.04	0.03	0.04
query39	0.03	0.03	0.03
query40	0.18	0.16	0.15
query41	0.10	0.03	0.03
query42	0.03	0.03	0.03
query43	0.04	0.04	0.03
Total cold run time: 96.54 s
Total hot run time: 24.87 s

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 58.05% (24568/42324)
Line Coverage 42.10% (245166/582375)
Region Coverage 38.00% (194713/512413)
Branch Coverage 39.10% (87721/224341)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100% (0/0) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 73.84% (30473/41269)
Line Coverage 57.88% (334830/578503)
Region Coverage 54.06% (277963/514178)
Branch Coverage 55.09% (123595/224371)

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