[llvm] 03d4904 - [dsymutil] Copy symbol table regardless of LINKEDIT segment
Jonas Devlieghere via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 25 13:24:45 PST 2022
Author: Jonas Devlieghere
Date: 2022-02-25T13:24:39-08:00
New Revision: 03d49046b9ca6ed3a33c21f87c45d525a1e320a7
URL: https://github.com/llvm/llvm-project/commit/03d49046b9ca6ed3a33c21f87c45d525a1e320a7
DIFF: https://github.com/llvm/llvm-project/commit/03d49046b9ca6ed3a33c21f87c45d525a1e320a7.diff
LOG: [dsymutil] Copy symbol table regardless of LINKEDIT segment
Ensure we copy the symbol table for MH_PRELOAD Mach-Os, which don't have
a LINKEDIT segment, but (can) have a symbol table.
rdar://88919473
Differential revision: https://reviews.llvm.org/D120583
Added:
llvm/test/tools/dsymutil/ARM/preload.test
llvm/test/tools/dsymutil/Inputs/private/tmp/preload/foo
llvm/test/tools/dsymutil/Inputs/private/tmp/preload/foo.o
Modified:
llvm/tools/dsymutil/MachOUtils.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/dsymutil/ARM/preload.test b/llvm/test/tools/dsymutil/ARM/preload.test
new file mode 100644
index 0000000000000..3caa4a22c4a03
--- /dev/null
+++ b/llvm/test/tools/dsymutil/ARM/preload.test
@@ -0,0 +1,10 @@
+$ cat foo.c
+void start(void) asm("start");
+void start(void) {}
+$ xcrun clang -c -o foo.o foo.c -g3
+$ xcrun clang -o foo foo.o -g3 -Wl,-preload -nodefaultlibs
+
+RUN: dsymutil -oso-prepend-path %p/../Inputs %p/../Inputs/private/tmp/preload/foo -o %t.dSYM
+RUN: llvm-nm %p/../Inputs/private/tmp/preload/foo | FileCheck %s
+RUN: llvm-nm %t.dSYM/Contents/Resources/DWARF/foo | FileCheck %s
+CHECK: start
diff --git a/llvm/test/tools/dsymutil/Inputs/private/tmp/preload/foo b/llvm/test/tools/dsymutil/Inputs/private/tmp/preload/foo
new file mode 100755
index 0000000000000..db45a8e5c1621
Binary files /dev/null and b/llvm/test/tools/dsymutil/Inputs/private/tmp/preload/foo
diff er
diff --git a/llvm/test/tools/dsymutil/Inputs/private/tmp/preload/foo.o b/llvm/test/tools/dsymutil/Inputs/private/tmp/preload/foo.o
new file mode 100644
index 0000000000000..2b2df029d5834
Binary files /dev/null and b/llvm/test/tools/dsymutil/Inputs/private/tmp/preload/foo.o
diff er
diff --git a/llvm/tools/dsymutil/MachOUtils.cpp b/llvm/tools/dsymutil/MachOUtils.cpp
index 26a278651ccd3..b4f3f334ba012 100644
--- a/llvm/tools/dsymutil/MachOUtils.cpp
+++ b/llvm/tools/dsymutil/MachOUtils.cpp
@@ -336,15 +336,6 @@ static bool isExecutable(const object::MachOObjectFile &Obj) {
return Obj.getHeader().filetype != MachO::MH_OBJECT;
}
-static bool hasLinkEditSegment(const object::MachOObjectFile &Obj) {
- bool HasLinkEditSegment = false;
- iterateOnSegments(Obj, [&](const MachO::segment_command_64 &Segment) {
- if (StringRef("__LINKEDIT") == Segment.segname)
- HasLinkEditSegment = true;
- });
- return HasLinkEditSegment;
-}
-
static unsigned segmentLoadCommandSize(bool Is64Bit, unsigned NumSections) {
if (Is64Bit)
return sizeof(MachO::segment_command_64) +
@@ -396,7 +387,9 @@ bool generateDsymCompanion(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
unsigned LoadCommandSize = 0;
unsigned NumLoadCommands = 0;
- // Get LC_UUID and LC_BUILD_VERSION.
+ bool HasSymtab = false;
+
+ // Check LC_SYMTAB and get LC_UUID and LC_BUILD_VERSION.
MachO::uuid_command UUIDCmd;
SmallVector<MachO::build_version_command, 2> BuildVersionCmd;
memset(&UUIDCmd, 0, sizeof(UUIDCmd));
@@ -420,14 +413,16 @@ bool generateDsymCompanion(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS,
BuildVersionCmd.push_back(Cmd);
break;
}
+ case MachO::LC_SYMTAB:
+ HasSymtab = true;
+ break;
default:
break;
}
}
// If we have a valid symtab to copy, do it.
- bool ShouldEmitSymtab =
- isExecutable(InputBinary) && hasLinkEditSegment(InputBinary);
+ bool ShouldEmitSymtab = HasSymtab && isExecutable(InputBinary);
if (ShouldEmitSymtab) {
LoadCommandSize += sizeof(MachO::symtab_command);
++NumLoadCommands;
More information about the llvm-commits
mailing list