[lld] [LLD][AARCH64] lld incorrectly handles .eh_frame when it has a non-zero offset within its output section. (PR #65966)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 11:05:48 PDT 2023


================
@@ -770,6 +770,9 @@ void AArch64::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
   uint64_t secAddr = sec.getOutputSection()->addr;
   if (auto *s = dyn_cast<InputSection>(&sec))
     secAddr += s->outSecOff;
+  else if (auto *eh = dyn_cast<EhInputSection>(&sec))
----------------
smithp35 wrote:

OK, reading through the code. The .ARM.exidx sections were also InputSections so we could alter their outSecOff to compensate. However EhInputSections are not InputSections so this won't work here. We need to find the outSecOff of the ehframe section (which is usually 0, but with some linker scripts isn't).

I don't know of a legal EhInputSection that would return getParent() == nullptr so it should be possible to remove the nested if.

I suggest use ehIn and ehFrame to make it a bit clearer which sections we are referring to. I've use SyntheticSection as it is what EhInputSection getParent() although that is derived from InputSection so in the code below InputSection would work too.
```
if (auto *ehIn = dyn_cast<EhInputSection>(&sec) {
  SyntheticSection *ehFrame = ehIn->getParent();
  SecAddr += ehFrame->outSecOff; 
}
```

https://github.com/llvm/llvm-project/pull/65966


More information about the llvm-commits mailing list