This is an archive of the discontinued LLVM Phabricator instance.

[ASan] Added .section statement to each function so they can be removed by --gc-sections.
ClosedPublic

Authored by kstoimenov on Mar 16 2022, 8:36 AM.

Diff Detail

Event Timeline

kstoimenov created this revision.Mar 16 2022, 8:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2022, 8:36 AM
kstoimenov requested review of this revision.Mar 16 2022, 8:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 16 2022, 8:36 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript

LGTM

compiler-rt/lib/asan/asan_rtl_x86_64.S
17

If we don't support binutils<2.35 (compiler-rt is built by GCC), we may use .section .text,"ax",%progbits,unique,__COUNTER__ ;\ to save a few bytes in the string table.

How old GCC do we support for compiler-rt?

MaskRay accepted this revision.Mar 16 2022, 10:22 AM

so they can be removed by --gc-sections.

This is not accurate. --gc-sections can apply to the monolithic .text with all callbacks. If all callbacks are unused, the whole .text is discarded.
It's probably just unrealistic for a large application where at least some are nearly guaranteed to be used.

Adding .section directives switches to fragmented text sections, which can be individually discarded.
Since we assume that a large portion of callbacks will not be called in a typical application, this can save a lot of space in the linker output.

This revision is now accepted and ready to land.Mar 16 2022, 10:22 AM
kstoimenov added inline comments.Mar 16 2022, 10:34 AM
compiler-rt/lib/asan/asan_rtl_x86_64.S
17

Thanks for the hint. I will submit as because saving few bytes is not worth risking version complications.