[llvm-bugs] [Bug 40364] New: Handling of extern globals in WebAssembly

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jan 17 10:58:10 PST 2019


            Bug ID: 40364
           Summary: Handling of extern globals in WebAssembly
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: All Bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: alonzakai at gmail.com
                CC: llvm-bugs at lists.llvm.org, peter.smith at linaro.org

They seem to be turned into address 0:

extern "C" int foo;
int main() {
  return foo;

==>  emcc a.cpp -o a.bc  ==>

@foo = external global i32, align 4

; Function Attrs: noinline norecurse nounwind optnone
define hidden i32 @main() #0 {
  %retval = alloca i32, align 4
  store i32 0, i32* %retval, align 4
  %0 = load i32, i32* @foo, align 4
  %inc = add nsw i32 %0, 1
  store i32 %inc, i32* @foo, align 4
  %1 = load i32, i32* @foo, align 4
  ret i32 %1

==>  wasm-ld a.bc -o a.wasm --entry=main --no-gc-sections --export-dynamic  ==>

 (func $main (; 1 ;) (type $1) (result i32)
   (i32.const 0)
     (i32.const 0)
    (i32.const 1)
   (i32.const 0)

Perhaps they should be handled like extern functions, that is, an import would
be emitted, something like

 (import "env" "foo" (global $gimport$0 i32))

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/20190117/36ea35f1/attachment.html>

More information about the llvm-bugs mailing list