Skip to content

Conversation

@DavidSpickett
Copy link
Collaborator

@DavidSpickett DavidSpickett commented Dec 19, 2024

$ ./bin/clang /tmp/test.c -o /tmp/test.o -target aarch64-linux -march=armv8+memtag -fsanitize=memtag-stack
clang: error: unsupported option '-fsanitize=memtag*' for target 'aarch64-unknown-linux'

But this works:

$ ./bin/clang /tmp/test.c -o /tmp/test.o --target=aarch64-linux-android -march=armv8+memtag -fsanitize=memtag-stack

Due to this check in Clang:

if (SanArgs.hasMemTag()) {

Likely because the required notes and dynamic loader support only exist for Android.

You can get around this, sort of, by not linking the file. However this means you have to provide your own way of loading it, so it doesn't change the statement that this feature is Android only.

#64692 also confirms that the intent is to only support Android at this time.

And while I'm here, suggest an additive set of flags that can also be used.

```
$ ./bin/clang /tmp/test.c -o /tmp/test.o -target aarch64-linux -march=armv8+memtag -fsanitize=memtag-stack
clang: error: unsupported option '-fsanitize=memtag*' for target 'aarch64-unknown-linux'
```
But this works:
```
$ ./bin/clang /tmp/test.c -o /tmp/test.o -target aarch64-linux-android -march=armv8+memtag -fsanitize=memtag-stack
```

Due to this check in Clang:
https://github.com/llvm/llvm-project/blob/2210da3b823ccf21fc634c858827c9f12c864b51/clang/lib/Driver/ToolChains/CommonArgs.cpp#L1651

Likely because the required notes and dynamic loader support only
exist for Android.

You can get around this, sort of, by not linking the file. However
this means you have to provide your own way of loading it, so it
doesn't change the statement that this feature is Android only.
@llvmbot
Copy link
Member

llvmbot commented Dec 19, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: David Spickett (DavidSpickett)

Changes
$ ./bin/clang /tmp/test.c -o /tmp/test.o -target aarch64-linux -march=armv8+memtag -fsanitize=memtag-stack
clang: error: unsupported option '-fsanitize=memtag*' for target 'aarch64-unknown-linux'

But this works:

$ ./bin/clang /tmp/test.c -o /tmp/test.o -target aarch64-linux-android -march=armv8+memtag -fsanitize=memtag-stack

Due to this check in Clang:

if (SanArgs.hasMemTag()) {

Likely because the required notes and dynamic loader support only exist for Android.

You can get around this, sort of, by not linking the file. However this means you have to provide your own way of loading it, so it doesn't change the statement that this feature is Android only.

#64692 also confirms that the intent is to only support Android at this time.


Full diff: https://github.com/llvm/llvm-project/pull/120545.diff

1 Files Affected:

  • (modified) llvm/docs/MemTagSanitizer.rst (+2-2)
diff --git a/llvm/docs/MemTagSanitizer.rst b/llvm/docs/MemTagSanitizer.rst
index 62efbfb041cbd0..44d261bec028f9 100644
--- a/llvm/docs/MemTagSanitizer.rst
+++ b/llvm/docs/MemTagSanitizer.rst
@@ -29,9 +29,9 @@ Usage
 =====
 
 Compile and link your program with ``-fsanitize=memtag`` flag. This
-will only work when targeting AArch64 with MemTag extension. One
+will only work when targeting AArch64 Android with MemTag extension. One
 possible way to achieve that is to add ``-target
-aarch64-linux -march=armv8+memtag`` to compilation flags.
+aarch64-linux-android -march=armv8+memtag`` to compilation flags.
 
 Implementation
 ==============

Copy link
Contributor

@fmayer fmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@DavidSpickett DavidSpickett merged commit 2fa2c21 into llvm:main Dec 20, 2024
6 of 8 checks passed
@DavidSpickett DavidSpickett deleted the memtag branch December 20, 2024 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants