llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Adrian Prantl (adrian-prantl)

<details>
<summary>Changes</summary>

On 32-bit ARM and x86, Mach-O uses scattered relocations, which identify their 
target by address. Relocatable DWARF puts every __DWARF section at address 0, 
so these relocations become ambiguous: a line table's reference to a file name 
in __debug_line_str resolves to the first function in __text instead.

Don't enable relocatable DWARF for these architectures.

Assisted-by: Claude

---
Full diff: https://github.com/llvm/llvm-project/pull/244069.diff


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+5) 
- (modified) clang/test/Driver/relocatable-dwarf.c (+15-2) 


``````````diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index b7a263c18b146..cec0ebc2564a8 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -682,6 +682,11 @@ void tools::addLinkerCompressDebugSectionsOption(
 
 bool tools::useMachORelocatableDwarf(const llvm::Triple &T,
                                      unsigned DwarfVersion) {
+  // 32-bit ARM and x86 Mach-O refer to a section plus an offset with a
+  // scattered relocation, which identifies its target by address. With every
+  // __DWARF section at address 0, that address is ambiguous.
+  if (T.isARM() || T.isThumb() || T.getArch() == llvm::Triple::x86)
+    return false;
   return T.isOSBinFormatMachO() && DwarfVersion >= 5 &&
          !(T.isMacOSX() || T.isiOS() || T.isWatchOS() || T.isXROS() ||
            T.isDriverKit());
diff --git a/clang/test/Driver/relocatable-dwarf.c 
b/clang/test/Driver/relocatable-dwarf.c
index c4830801ebf7a..2ba1c8685a1dc 100644
--- a/clang/test/Driver/relocatable-dwarf.c
+++ b/clang/test/Driver/relocatable-dwarf.c
@@ -1,6 +1,7 @@
 // Mach-O objects with DWARF 5 or later relocate offsets between DWARF 
sections,
-// except for the Apple operating systems below. This applies to code
-// generation, the integrated assembler, and LTO code generation in the linker.
+// except for the Apple operating systems and 32-bit ARM and x86 below. This
+// applies to code generation, the integrated assembler, and LTO code 
generation
+// in the linker.
 
 // RUN: %clang -### --target=arm64-apple-none-macho -g -c %s 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CC1
@@ -31,6 +32,18 @@
 // RUN:   | FileCheck %s --check-prefix=NONE
 // RUN: %clang -### --target=x86_64-linux-gnu -g -c %s 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=NONE
+// RUN: %clang -### --target=armv7em-apple-none-macho -g -c %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=NONE
+// RUN: %clang -### --target=armv7em-apple-none-macho -g -c -x assembler %s 
2>&1 \
+// RUN:   | FileCheck %s --check-prefix=NONE
+// RUN: %clang -### --target=armv7em-apple-none-macho -g -flto %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=NONE
+// RUN: %clang -### --target=i386-apple-none-macho -g -c %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=NONE
+// RUN: %clang -### --target=i386-apple-none-macho -g -c -x assembler %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=NONE
+// RUN: %clang -### --target=i386-apple-none-macho -g -flto %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=NONE
 
 // CC1:   "-cc1" {{.*}}"-grelocatable-dwarf"
 // CC1AS: "-cc1as" {{.*}}"-grelocatable-dwarf"

``````````

</details>


https://github.com/llvm/llvm-project/pull/244069
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to