[lld] [lld][MachO] Warn on underaligned arm64 functions (PR #221636)
Chak-Kuen Lam via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 19:46:07 PDT 2026
================
@@ -896,6 +896,23 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section> sectionHeaders,
return StringRef(strtab + sym.n_strx);
};
+ // arm64 instructions must be 4-byte aligned, so a symbol in a code section
+ // whose guaranteed alignment is lower than that names a function that can
+ // never be executed. ld64 diagnoses this, so we do too. Note that we check
+ // each symbol rather than each subsection: an alt-entry symbol does not
+ // induce a new subsection, but it is still an entry point that has to be
+ // aligned.
+ const bool checkCodeAlign = target->cpuType == CPU_TYPE_ARM64 &&
+ (sections[i]->flags & S_ATTR_PURE_INSTRUCTIONS);
+
+ // Mach-O reserves the 'l' and 'L' prefixes for labels that the assembler
+ // generates for its own use, such as the ltmp0 anchor it emits for each
+ // section. Those do not name functions, so ld64 does not warn about them.
+ auto isAssemblerTemp = [](const NList &sym, StringRef name) {
+ return !(sym.n_type & N_EXT) &&
+ (name.starts_with("l") || name.starts_with("L"));
----------------
dukecat0 wrote:
`isPrivateLabel` treats all `l`/`L`-prefixed names as private, which doesn't work for the example you provided here.
https://github.com/llvm/llvm-project/pull/221636
More information about the llvm-commits
mailing list