[PATCH] D137370: [lld-macho] Fix bugs around EH_Frame symbols
Jez Ng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 3 15:38:26 PDT 2022
int3 created this revision.
int3 added a reviewer: lld-macho.
Herald added projects: lld-macho, All.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
While extending the map file to cover unwind info, I realized we had two
issues with our EH_Frame symbols:
1. Their size was not set
2. We would create two EH_Frame symbols per frame when we only needed one. This was because the Defined constructor would add the symbol itself to InputSection::symbols, but we were also manually appending the symbol to that same vector.
Note that ld64 prints "CIE" and "FDE for: <function>" instead of just
"EH_Frame", but I'm punting on that for now unless we discover that
users really depend upon it.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D137370
Files:
lld/MachO/InputFiles.cpp
lld/MachO/MapFile.cpp
lld/test/MachO/map-file.s
Index: lld/test/MachO/map-file.s
===================================================================
--- lld/test/MachO/map-file.s
+++ lld/test/MachO/map-file.s
@@ -8,7 +8,9 @@
# RUN: --time-trace -o %t/test
# RUN: llvm-objdump --syms --section-headers %t/test > %t/objdump
## Check that symbols in cstring sections aren't emitted
-# RUN: cat %t/objdump %t/map | FileCheck %s --implicit-check-not _hello_world
+## Also check that we don't have redundant EH_Frame symbols (regression test)
+# RUN: cat %t/objdump %t/map | FileCheck %s --implicit-check-not _hello_world \
+# RUN: --implicit-check-not EH_Frame
# RUN: FileCheck %s --check-prefix=MAPFILE < %t/test.time-trace
# CHECK: Sections:
@@ -44,15 +46,18 @@
# CHECK-NEXT: 0x[[#%X,BSS]] 0x{{[0-9A-F]+}} __DATA __common
# CHECK-NEXT: # Symbols:
-# CHECK-NEXT: # Address Size File Name
-# CHECK-DAG: 0x[[#%X,MAIN]] 0x00000001 [ 1] _main
-# CHECK-DAG: 0x[[#%X,BAR]] 0x00000001 [ 1] _bar
-# CHECK-DAG: 0x[[#%X,FOO]] 0x00000001 [ 2] __ZTIN3foo3bar4MethE
-# CHECK-DAG: 0x[[#%X,HIWORLD]] 0x0000000E [ 3] literal string: Hello world!\n
-# CHECK-DAG: 0x[[#%X,HIITSME]] 0x0000000F [ 3] literal string: Hello, it's me
-# CHECK-DAG: 0x[[#%X,HIITSME + 0xf]] 0x0000000E [ 3] literal string: Hello world!\n
-# CHECK-DAG: 0x[[#%X,NUMBER]] 0x00000001 [ 1] _number
-# CHECK-DAG: 0x[[#%X,UNWIND]] 0x0000103C [ 0] compact unwind info
+# CHECK-NEXT: # Address Size File Name
+# CHECK-DAG: 0x[[#%X,MAIN]] 0x00000001 [ 1] _main
+# CHECK-DAG: 0x[[#%X,BAR]] 0x00000001 [ 1] _bar
+# CHECK-DAG: 0x[[#%X,FOO]] 0x00000001 [ 2] __ZTIN3foo3bar4MethE
+# CHECK-DAG: 0x[[#%X,HIWORLD]] 0x0000000E [ 3] literal string: Hello world!\n
+# CHECK-DAG: 0x[[#%X,HIITSME]] 0x0000000F [ 3] literal string: Hello, it's me
+# CHECK-DAG: 0x[[#%X,HIITSME + 0xf]] 0x0000000E [ 3] literal string: Hello world!\n
+# CHECK-DAG: 0x[[#%X,NUMBER]] 0x00000001 [ 1] _number
+# CHECK-DAG: 0x[[#%X,UNWIND]] 0x0000103C [ 0] compact unwind info
+## Note: ld64 prints "CIE" and "FDE for: <function>" instead of "EH_Frame".
+# CHECK-DAG: 0x[[#%X,EH_FRAME]] 0x00000018 [ 1] EH_Frame
+# CHECK-DAG: 0x[[#%X,EH_FRAME + 0x18]] 0x00000020 [ 1] EH_Frame
# MAPFILE: "name":"Total Write map file"
Index: lld/MachO/MapFile.cpp
===================================================================
--- lld/MachO/MapFile.cpp
+++ lld/MachO/MapFile.cpp
@@ -184,6 +184,9 @@
info.fileIndex);
os.write_escaped(info.str) << "\n";
}
+ } else if (osec == (void *)in.unwindInfo) {
+ os << format("0x%08llX\t0x%08llX\t[ 0] compact unwind info\n",
+ osec->addr, osec->getSize());
}
// TODO print other synthetic sections
}
Index: lld/MachO/InputFiles.cpp
===================================================================
--- lld/MachO/InputFiles.cpp
+++ lld/MachO/InputFiles.cpp
@@ -1347,11 +1347,11 @@
// that all EH frames have an associated symbol so that we can generate
// subtractor relocs that reference them.
if (isec->symbols.size() == 0)
- isec->symbols.push_back(make<Defined>(
- "EH_Frame", isec->getFile(), isec, /*value=*/0, /*size=*/0,
- /*isWeakDef=*/false, /*isExternal=*/false, /*isPrivateExtern=*/false,
- /*includeInSymtab=*/false, /*isThumb=*/false,
- /*isReferencedDynamically=*/false, /*noDeadStrip=*/false));
+ make<Defined>("EH_Frame", isec->getFile(), isec, /*value=*/0,
+ isec->getSize(), /*isWeakDef=*/false, /*isExternal=*/false,
+ /*isPrivateExtern=*/false, /*includeInSymtab=*/false,
+ /*isThumb=*/false, /*isReferencedDynamically=*/false,
+ /*noDeadStrip=*/false);
else if (isec->symbols[0]->value != 0)
fatal("found symbol at unexpected offset in __eh_frame");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137370.473062.patch
Type: text/x-patch
Size: 4115 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221103/af9a4ef6/attachment.bin>
More information about the llvm-commits
mailing list