LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 39218 - i686 mingw-w64 comdat functions use wrong .text section name
Summary: i686 mingw-w64 comdat functions use wrong .text section name
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: X86 (show other bugs)
Version: trunk
Hardware: PC Windows NT
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks: release-7.0.1
  Show dependency tree
 
Reported: 2018-10-08 14:01 PDT by Reid Kleckner
Modified: 2018-11-29 16:09 PST (History)
3 users (show)

See Also:
Fixed By Commit(s): r347431 r347931


Attachments
Potential fix (1.49 KB, patch)
2018-11-11 06:59 PST, Andrew Yohn
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Reid Kleckner 2018-10-08 14:01:12 PDT
If you simply build and run the example from the original mingw-w64 comdat ABI compatibility bug (https://github.com/Alexpux/MINGW-packages/issues/1677#issuecomment-394906508, also below) for i686, it shows we don't use the right section names:

$ cat a.cpp
inline int foo(int a, int b) { return a + b; }
int bar(void);
int main() { return foo(1, 2) + bar(); }

$ cat b.cpp
inline int foo(int a, int b) { return a + b; }
int bar() { return foo(3, 4); }

$ gcc -m32 a.cpp -c -o a.o && clang --target=i686-w64-windows-gnu -c b.cpp -o b.o 

$ dumpbin a.o | grep text
          34 .text
          10 .text$_Z3fooii

$ dumpbin b.o | grep text
          1F .text
          1F .text$__Z3fooii

Clang adds the extra '_' for Windows C symbol mangling, but GCC does not.

A user emailed me directly to report that they were getting linker errors, but I have not been able to observe any problems caused by this mismatch.
Comment 1 Andrew Yohn 2018-11-11 06:59:26 PST
Created attachment 21109 [details]
Potential fix

The attached 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.
Comment 2 Andrew Yohn 2018-11-18 08:09:09 PST
Please consider for 7.0.1 release. This prevents using Clang 7 on i686 Windows NT. Thank you.
Comment 3 Andrew Yohn 2018-11-18 08:12:00 PST
(In reply to Andrew Yohn from comment #2)
> Please consider for 7.0.1 release. This prevents using Clang 7 on i686
> Windows NT. Thank you.

Sorry, that should have read, "This prevents using Clang 7 for i686 Windows NT with GCC/mingw-w64."
Comment 4 Tom Stellard 2018-11-19 16:38:11 PST
Has this patch been submitted to phabricator?
Comment 5 Andrew Yohn 2018-11-20 09:42:35 PST
(In reply to Tom Stellard from comment #4)
> Has this patch been submitted to phabricator?

Sorry, I'm new to this process. I've created a review now. https://reviews.llvm.org/D54762
Comment 6 Reid Kleckner 2018-11-21 14:04:58 PST
Tom, feel free to merge r347431 to 7.0.1, although you might want to let it bake in tree for a few days.
Comment 7 Andrew Yohn 2018-11-25 16:27:13 PST
Added bug 39781 to track the merge.