[llvm-bugs] [Bug 35467] New: WASM backend fails on multiple symbols in same section for ctors

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Nov 29 10:56:35 PST 2017


https://bugs.llvm.org/show_bug.cgi?id=35467

            Bug ID: 35467
           Summary: WASM backend fails on multiple symbols in same section
                    for ctors
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: WebAssembly
          Assignee: unassignedbugs at nondot.org
          Reporter: ncw at realvnc.com
                CC: llvm-bugs at lists.llvm.org

When compiling simple code with a C++ constructor, the WASM backend refuses to
emit the code with the following error from WasmObjectWriter.cpp:

>  LLVM ERROR: function sections must contain one function each


The error only occurs when compiling with "-O0", and does not occur when
compiling with "-Os".

I think this is a distinct problem to the one observed in
https://bugs.llvm.org/show_bug.cgi?id=35414.


=== Full testcase ===

### C++ code:

struct WithCtor {
  WithCtor();
};
WithCtor::WithCtor() {}

static WithCtor withCtor;


### LLVM output from "clang++ -O0 -emit-llvm"

%struct.WithCtor = type { i8 }

@_ZL8withCtor = internal global %struct.WithCtor zeroinitializer, align 1
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void
()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_init_test.cxx, i8* null }]

@_ZN8WithCtorC1Ev = hidden alias %struct.WithCtor* (%struct.WithCtor*),
%struct.WithCtor* (%struct.WithCtor*)* @_ZN8WithCtorC2Ev

; Function Attrs: noinline nounwind optnone
define hidden %struct.WithCtor* @_ZN8WithCtorC2Ev(%struct.WithCtor* returned
%this) unnamed_addr #0 {
entry:
  %this.addr = alloca %struct.WithCtor*, align 4
  store %struct.WithCtor* %this, %struct.WithCtor** %this.addr, align 4
  %this1 = load %struct.WithCtor*, %struct.WithCtor** %this.addr, align 4
  ret %struct.WithCtor* %this1
}

; Function Attrs: noinline
define internal void @__cxx_global_var_init() #1 section ".text.__startup" {
entry:
  %call = call %struct.WithCtor* @_ZN8WithCtorC1Ev(%struct.WithCtor*
@_ZL8withCtor)
  ret void
}

; Function Attrs: noinline
define internal void @_GLOBAL__sub_I_init_test.cxx() #1 section
".text.__startup" {
entry:
  call void @__cxx_global_var_init()
  ret void
}


### Fails when compiled with "llc -filetype=obj output.o"

-- 
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/20171129/da950201/attachment.html>


More information about the llvm-bugs mailing list