[PATCH] D54762: i686 mingw-w64 comdat functions use wrong .text section name

Andrew Yohn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 20 09:42:04 PST 2018


herman6067 created this revision.
herman6067 added reviewers: rnk, craig.topper.
Herald added subscribers: llvm-commits, hiraditya.

Fix for bug 39218 <https://bugs.llvm.org/show_bug.cgi?id=39218>

This patch seems to fix this issue. However, from a code standpoint, I'm not sure it is up to standards. I am submitting this to see if it is directionally correct, and seeking feedback for a better way to accomplish this.

Questions I have:

1. Are the modifications to the test correct? The code seems to function (it passes `check-llvm`, `check-clang`, and manual testing of the example with GCC). I am not very familiar with comdats or COFF, and therefore I am not 100% confident in the test case.
2. Is GO->getComdat()->getName() the correct place to get the name, or is it a coincidence that it contains the right data?

Any feedback is welcome, and I am happy to submit another patch incorporating any suggested changes.


Repository:
  rL LLVM

https://reviews.llvm.org/D54762

Files:
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/test/CodeGen/X86/mingw-comdats.ll


Index: llvm/test/CodeGen/X86/mingw-comdats.ll
===================================================================
--- llvm/test/CodeGen/X86/mingw-comdats.ll
+++ llvm/test/CodeGen/X86/mingw-comdats.ll
@@ -50,9 +50,9 @@
 ; GNU: gv:
 ; GNU: .long 42
 
-; GNU32: .section        .text$__Z3fooi,"xr",discard,__Z3fooi
+; GNU32: .section        .text$_Z3fooi,"xr",discard,__Z3fooi
 ; GNU32: __Z3fooi:
-; GNU32: .section        .data$_gv,"dw",discard,_gv
+; GNU32: .section        .data$gv,"dw",discard,_gv
 ; GNU32: _gv:
 ; GNU32: .long 42
 
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1319,8 +1319,13 @@
 
       // Append "$symbol" to the section name when targetting mingw. The ld.bfd
       // COFF linker will not properly handle comdats otherwise.
-      if (getTargetTriple().isWindowsGNUEnvironment())
-        raw_svector_ostream(Name) << '$' << COMDATSymName;
+      if (getTargetTriple().isWindowsGNUEnvironment()) {
+        if (getTargetTriple().isArch32Bit()) {
+          raw_svector_ostream(Name) << '$' << GO->getComdat()->getName();
+        } else {
+          raw_svector_ostream(Name) << '$' << COMDATSymName;
+        }
+      }
 
       return getContext().getCOFFSection(Name, Characteristics, Kind,
                                          COMDATSymName, Selection, UniqueID);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54762.174803.patch
Type: text/x-patch
Size: 1489 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181120/b547c536/attachment.bin>


More information about the llvm-commits mailing list