llvm / llvm/llvm-project

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

Open
#166,380 3 comments 0 reactions 0 assignees View on GitHub
compiler-rt:asan
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.