Skip to content

-fsanitize=memtag-globals doesn't tag global variables in the presence of __attribute__ section #166380

@tarcisiofischer

Description

@tarcisiofischer

The following program:

__attribute__((section("foo_section"))) int foo = 42;
int main() { return foo; }

compiled with -fsanitize=memtag-globals yields

$ llvm-readelf --memtag a.out
Memtag Dynamic Entries:                 
    AARCH64_MEMTAG_MODE: Synchronous (0)
    AARCH64_MEMTAG_HEAP: Disabled (0)   
    AARCH64_MEMTAG_STACK: Disabled (0)  
Memtag Android Note:                    
    Tagging Mode: SYNC                  
    Heap: Disabled                      
    Stack: Disabled                     

I'd expect the same result as:

int foo = 42;
int main() { return foo; }
$ llvm-readelf --memtag a.out
Memtag Dynamic Entries:
    AARCH64_MEMTAG_MODE: Synchronous (0)
    AARCH64_MEMTAG_HEAP: Disabled (0)
    AARCH64_MEMTAG_STACK: Disabled (0)
    AARCH64_MEMTAG_GLOBALS: 0x338
    AARCH64_MEMTAG_GLOBALSSZ: 3
Memtag Android Note:
    Tagging Mode: SYNC
    Heap: Disabled
    Stack: Disabled
Memtag Global Descriptors:
    0x89b0: 0x10

The reason seems to be the following code: https://github.com/llvm/llvm-project/blob/main/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp#L2608-L2627

I tried removing this code, and I can confirm the memory in the section is tagged, and my test executable runs just fine 👍 But I didn't run into any of the issues mentioned in the comments... So I'm creating this issue hoping to either remove that bit of code or to understand more about the issues mentioned in the comments. (Marking @fmayer since he appears in the blame in that code)

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions