[lld] [llvm] [lld][AArch64][Build Attributes] Add support for converting AArch64 Build Attributes to GNU Properties (PR #131990)
Jack Styles via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 14 09:04:02 PDT 2025
================
@@ -539,6 +541,156 @@ uint32_t ObjFile<ELFT>::getSectionIndex(const Elf_Sym &sym) const {
this);
}
+template <typename ELFT>
+static void parseGnuPropertyNote(Ctx &ctx, ELFFileBase &f,
+ uint32_t featureAndType,
+ ArrayRef<uint8_t> &desc, const uint8_t *base,
+ ArrayRef<uint8_t> *data = nullptr) {
+ auto err = [&](const uint8_t *place) -> ELFSyncStream {
+ auto diag = Err(ctx);
+ diag << &f << ":(" << ".note.gnu.property+0x"
+ << Twine::utohexstr(place - base) << "): ";
+ return diag;
+ };
+
+ while (!desc.empty()) {
+ const uint8_t *place = desc.data();
+ if (desc.size() < 8)
+ return void(err(place) << "program property is too short");
+ uint32_t type = read32<ELFT::Endianness>(desc.data());
+ uint32_t size = read32<ELFT::Endianness>(desc.data() + 4);
+ desc = desc.slice(8);
+ if (desc.size() < size)
+ return void(err(place) << "program property is too short");
+
+ if (type == featureAndType) {
+ // We found a FEATURE_1_AND field. There may be more than one of these
+ // in a .note.gnu.property section, for a relocatable object we
+ // accumulate the bits set.
+ if (size < 4)
+ return void(err(place) << "FEATURE_1_AND entry is too short");
+ f.andFeatures |= read32<ELFT::Endianness>(desc.data());
+ } else if (ctx.arg.emachine == EM_AARCH64 &&
+ type == GNU_PROPERTY_AARCH64_FEATURE_PAUTH) {
+ ArrayRef<uint8_t> contents = data ? *data : desc;
+ if (!f.aarch64PauthAbiCoreInfo.empty()) {
+ return void(
+ err(contents.data())
+ << "multiple GNU_PROPERTY_AARCH64_FEATURE_PAUTH entries are "
+ "not supported");
+ } else if (size != 16) {
+ return void(err(contents.data())
+ << "GNU_PROPERTY_AARCH64_FEATURE_PAUTH entry "
+ "is invalid: expected 16 bytes, but got "
+ << size);
+ }
+ f.aarch64PauthAbiCoreInfo = desc;
+ }
+
+ // Padding is present in the note descriptor, if necessary.
+ desc = desc.slice(alignTo<(ELFT::Is64Bits ? 8 : 4)>(size));
+ }
+}
+// Read the following info from the .note.gnu.property section and write it to
----------------
Stylie777 wrote:
nit: Add a line of whitespace here to separate the previous function and the next.
https://github.com/llvm/llvm-project/pull/131990
More information about the llvm-commits
mailing list