[llvm-bugs] [Bug 51144] New: Clang / LLD crash linking object files with .bc instead of .o extension

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jul 20 10:47:16 PDT 2021


            Bug ID: 51144
           Summary: Clang / LLD crash linking object files with .bc
                    instead of .o extension
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: lukerissacher at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Created attachment 25037
  --> https://bugs.llvm.org/attachment.cgi?id=25037&action=edit
Minimal code for reproducing

Linking via the clang frontend plus a few common options (-g, -flto,
-fuse-ld=lld) always results in a hard crash when the bitcode object files have
their native .bc extension. Renaming them to .o resolves the error.

I've observed this in:

  clang version 13.0.0 on Windows x64
  clang version 10.0.0-4ubuntu1 on Linux

Sample code (also attached):


    #include "extra.h"

    int main() {
        return func1(42);


    extern int func1(int x);
    extern int func2(int x);


    #include "extra.h"

    int func1(int x) {
        return x * 2;

    int func2(int x) {
        return x * 3 + 1;

Steps to reproduce:

  clang -c -flto -g extra.c -o extra.bc
  clang -c -flto -g main.c -o main.bc
  clang -flto -g main.bc extra.bc -fuse-ld=lld -o out.exe

Output (Windows):

    module flag identifiers must be unique (or of 'require' type)
    LLVM ERROR: Broken module found, compilation aborted!
    PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash
    Stack dump:
    0.      Program arguments: "C:\\Program Files\\LLVM\\bin\\lld-link"
-out:out.exe -defaultlib:libcmt -defaultlib:oldnames "-libpath:C:\\Program
Files (x86)\\Microsoft Visual
"-libpath:C:\\Program Files (x86)\\Microsoft Visual
"-libpath:C:\\Program Files (x86)\\Windows
Kits\\10\\Lib\\10.0.18362.0\\ucrt\\x64" "-libpath:C:\\Program Files
(x86)\\Windows Kits\\10\\Lib\\10.0.18362.0\\um\\x64" -nologo -debug
    #0 0x00007ff7c4fe8305 C:\Program Files\LLVM\bin\lld-link.exe 0xc8305
(C:\Program Files\LLVM\bin\lld-link.exe+0xc8305)
    #1 0x00007ff7c4fe8305
    #2 0x00007ff7c4fe8305 (C:\Program Files\LLVM\bin\lld-link.exe+0xc8305)
    #3 0x00007ffdafaa1881 C:\Program Files\LLVM\bin\lld-link.exe 0x96f4e
C:\Program Files\LLVM\bin\lld-link.exe 0x96f71
    #4 0x00007ffdafaa1881 C:\Program Files\LLVM\bin\lld-link.exe 0x20ed441
C:\Program Files\LLVM\bin\lld-link.exe 0x1121625
    #5 0x00007ffdafaa1881 C:\Program Files\LLVM\bin\lld-link.exe 0x1120d3a
C:\Program Files\LLVM\bin\lld-link.exe 0x1120ac0
    #6 0x00007ffdafaa1881 C:\Program Files\LLVM\bin\lld-link.exe 0x1157a1
C:\Program Files\LLVM\bin\lld-link.exe 0x1188ec
    #7 0x00007ffdafaa1881 C:\Program Files\LLVM\bin\lld-link.exe 0xfe873
C:\Program Files\LLVM\bin\lld-link.exe 0xf8686
    #8 0x00007ffdafaa1881 C:\Program Files\LLVM\bin\lld-link.exe 0x6bc98
C:\Program Files\LLVM\bin\lld-link.exe 0x6c0f1
    #9 0x00007ffdafaa1881 C:\Program Files\LLVM\bin\lld-link.exe 0x21793f4
    #10 0x00007ffdafaa1881
    #11 0x00007ffdafaa1881 (C:\WINDOWS\System32\ucrtbase.dll+0x71881)
    0x00007FF7C4FE8305 (0x0000B749A057036E 0x000000141838FA88
0x0000000000000016 0x00007FF7C4FE8300)
    0x00007FFDAFAA1881 (0x0000000000000001 0x0000000000000000
0x0000000000000000 0x000000141838CF90), raise() + 0x1E1 bytes(s)
    0x00007FFDAFAA2851 (0x0000000000000003 0x0000000000000003
0x0000000000000000 0x000000141838D0C0), abort() + 0x31 bytes(s)
    0x00007FF7C4FB6F4E (0x000001B8D3A89640 0x00007FF7C6FFE41E
0x0000000000000001 0x000000141838D240)
    0x00007FF7C4FB6F71 (0x000001B8D3A89640 0x000001B8D3A89640
0x000000141838D240 0x000000141838D240)
    0x00007FF7C700D441 (0x00007FF7C7142620 0x0000000000000000
0x0000000000000000 0x00007FFDB1C9B86B)
    0x00007FF7C6041625 (0x000000141838D648 0x00007FFDB1C95BA1
0x0000000000000000 0x0000000000000006)
    0x00007FF7C6040D3A (0x0000000000000000 0x000001B800000000
0x000001B8D399BDC0 0x0000001400000000)
    0x00007FF7C6040AC0 (0x0000000000000000 0x0000000000000000
0x00007FF7C713CA00 0x0000000000000000)
    0x00007FF7C50357A1 (0x000001B8CE33DC30 0x000001B8CE2E5D50
0x0000000000000000 0x000001B8CE3137F0)
    0x00007FF7C50388EC (0x00007FF7C88336E8 0x0000000000000001
0x0000000000000001 0x00007FF7C88336E8)
    0x00007FF7C501E873 (0x00007FF7C889D8E0 0x000001B8CE3117D0
0x000001B8CE3117D0 0x000001B8CE3117D0)
    0x00007FF7C5018686 (0x000001B8CE2F3F80 0x000001B8CE2F3F10
0x00007FF7C889C890 0x00007FF7C889C820)
    0x00007FF7C4F8BC98 (0x00007FF7C889C890 0x0000000000000000
0x000001B8CE2F3F80 0x0000000000000000)
    0x00007FF7C4F8C0F1 (0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000)
    0x00007FF7C70993F4 (0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000)
    0x00007FFDB19D7034 (0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000), BaseThreadInitThunk() + 0x14 bytes(s)
    0x00007FFDB1CC2651 (0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000), RtlUserThreadStart() + 0x21 bytes(s)
    clang: error: linker command failed due to signal (use -v to see

To fix, simply rename the .bc files to .o and re-link:

    mv main.bc main.o
    mv extra.bc extra.o
    clang -flto -g main.o extra.o -fuse-ld=lld -o out.exe


Removing the -flto option from the final link command also works, but this
disables link-time optimizations in the final output machine code (for example
inlining func1() in the example).

Since the object files are actually bitcode, clang should support linking them
with their proper .bc extension.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210720/d4b02167/attachment-0001.html>

More information about the llvm-bugs mailing list