Do not instrument user-defined ELF sections (whose names resemble valid
C identifiers). They may have special use semantics and modifying them
may break programs. This is e.g. the case with NetBSD __link_set API
that expects these sections to store consecutive array elements.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
@lebedev.ri Can you point me to where this test needs to be added and an example of the same?
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | ||
---|---|---|
1859 | What do the names of these sections look like? From the test I presume that they have C identifier names and are enumerated via __start_/__stop_. In that case we should exclude all C identifier named sections from instrumentation (not just link_set*) in order to fix similar bugs involving those sections. |
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | ||
---|---|---|
1859 | They are created via the following macro: #define __link_set_make_entry(set, sym) \ static void const * const __link_set_##set##_sym_##sym \ __section("link_set_" #set) __used = (const void *)&sym So the link_set_ name is enforced on our end. Of course, people can do any crazy things they like, so can't tell if anyone else has a similar use case. |
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | ||
---|---|---|
1859 | Something like: if (ELF) { for (char C : Section) { if (!((C >= 'A' && C <= 'Z') || (C >= 'a' && C <= 'a') || (C >= '0' && C <= '9') || C == '_'))) return false; } } |
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp | ||
---|---|---|
1887 | Drive-by comment: if we don't instrument sections with names resembling valid C identifiers, then there should be a test checking that we instrument a section with a name that's an invalid identifier. |
Will adding attribute((no_sanitize("address"))) to your global solve the problem you are trying to solve?
(sorry for being too terse last time)
It does not work (last time I checked).
Also GCC does the same thing of not instrumenting user defined sections.
Does not work how?
Also GCC does the same thing of not instrumenting user defined sections.
I cannot get a user defined section uninstrumented without the proposed patch. Elements in such sections are not in consecutive order. This is a known problem and fixed by GCC in a similar way to this patch here.
Also reading the context of this patch, some other platforms have faced the same problem.
What do the names of these sections look like? From the test I presume that they have C identifier names and are enumerated via __start_/__stop_. In that case we should exclude all C identifier named sections from instrumentation (not just link_set*) in order to fix similar bugs involving those sections.