This is an archive of the discontinued LLVM Phabricator instance.

[lld] [MTE] Add DT_AARCH64_MEMTAG_* dynamic entries, and small cleanup
ClosedPublic

Authored by hctim on Feb 10 2023, 10:56 AM.

Details

Summary

Adds the new AArch64-ABI dynamic entry generation to LLD. This will
allow Android to move from the Android-specific ELF note onto the
dynamic entries.

Change the behaviour of an unspecified --android-memtag-mode. Now, when
unspecified, this will print a warning that you're doing a no-op, rather
than implicitly turning on sync mode. This is important for MTE globals
later, where a binary containing static tagged global descriptors
shouldn't have MTE turned on without specific intent being passed to the
linker.

For now, continue to emit the Android ELF note by default. In future, we
can probably make it only emit the note when provided a flag.

Do a quick NFC-cleanup of the ELF note while we're here. It doesn't
change anything about the ELF note itself, but makes it more clear to
the reader of the code what alignment requirements are being (previously
implicitly) met.

Diff Detail

Event Timeline

hctim created this revision.Feb 10 2023, 10:56 AM
hctim requested review of this revision.Feb 10 2023, 10:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2023, 10:56 AM
fmayer added inline comments.Feb 10 2023, 11:02 AM
lld/ELF/SyntheticSections.cpp
3853

should we have a static_assert that this is aligned to 4 instead? this seems like a no op

3868

as above

hctim added inline comments.Feb 10 2023, 11:15 AM
lld/ELF/SyntheticSections.cpp
3853

yeah, it's a no-op.

there's also already a static_assert that the note name == 8 bytes, so adding an aligned-4 assert is probably unnecessary.

the reason why i put this here is because i wanted anyone who comes along and copy-paste implements an ELF note to not bugger up the alignment. for example, this caught me off guard when implementing an MTE globals note in the previous design. course, anyone implementing ELF notes should probably be consulting the manpage which does mention the alignment, but yeah, can be easy to miss.

WDYT?

MaskRay added inline comments.Feb 10 2023, 11:17 PM
lld/ELF/Driver.cpp
739

delete blank line

lld/ELF/SyntheticSections.cpp
3853

Keeping align LGTM, as it documents the code without introducing runtime overhead (optimized out).

lld/test/ELF/aarch64-memtag-android-abi.s
59

Mention warning: for warnings. Don't use -SAME just to wrap lines.

Considering adding some documentation to lld/docs/ld.lld.1. It can contain more information than lld/ELF/Options.td

hctim marked 2 inline comments as done.Feb 13 2023, 10:01 AM

Considering adding some documentation to lld/docs/ld.lld.1. It can contain more information than lld/ELF/Options.td

I think it might be better to leave it off the manpage for now, given:

  1. MTE binaries should generally be linked via. an invocation of clang, much like other sanitizers.
  2. Right now, this is only an android-specific feature, so normal developers shouldn't be touching these flags, as it should all be done via. the build system. Not even NDK developers should be using them for now. Maybe once we genericize the API to be --aarch64 rather than --android, we can consider.
hctim updated this revision to Diff 497030.Feb 13 2023, 10:02 AM

Update the test a little to be explicit about warning/error, remove a newline.

@fmayer / @MaskRay , would you mind taking a quick second pass? thanks

MaskRay accepted this revision.Feb 17 2023, 2:08 PM

LGTM.

This revision is now accepted and ready to land.Feb 17 2023, 2:08 PM
fmayer accepted this revision.Feb 21 2023, 1:09 PM
This revision was landed with ongoing or failed builds.Mar 1 2023, 11:14 AM
This revision was automatically updated to reflect the committed changes.