<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - wasm-ld does not link globals"
   href="https://bugs.llvm.org/show_bug.cgi?id=41726">41726</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>wasm-ld does not link globals
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mail@joachim-breitner.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider this example:

$ cat a.c
int foo = '!';

int get_foo_a() { return foo; };
$ cat b.c
extern int foo;

int get_foo_b() { return foo; };
$ clang-9 --compile -fpic --target=wasm32-unknown-unknown-wasm a.c
$ clang-9 --compile -fpic --target=wasm32-unknown-unknown-wasm b.c
$ wasm-ld-9 --import-memory --shared --no-entry a.o b.o -o foo.wasm --export
get_foo_a --export get_foo_b

I would now expect both functions to use the same value for foo. But the
resulting file still has an unresolved import of GOT.mem.foo:

$ wasm-dis foo.wasm
(module
 (type $0 (func))
 (type $1 (func (result i32)))
 (import "env" "memory" (memory $0 0))
 (import "env" "__indirect_function_table" (table 0 anyfunc))
 (import "env" "__memory_base" (global $gimport$2 i32))
 (import "env" "__table_base" (global $gimport$3 i32))
 (import "GOT.mem" "foo" (global $gimport$4 i32))
 (data (get_global $gimport$2) "!\00\00\00")
 (export "get_foo_a" (func $get_foo_a))
 (export "get_foo_b" (func $get_foo_b))
 (func $__wasm_call_ctors (; 0 ;) (type $0)
  (call $__wasm_apply_relocs)
 )
 (func $__wasm_apply_relocs (; 1 ;) (type $0)
 )
 (func $get_foo_a (; 2 ;) (type $1) (result i32)
  (local $var$0 i32)
  (local $var$1 i32)
  (local $var$2 i32)
  (local $var$3 i32)
  (set_local $var$0
   (i32.const 0)
  )
  (set_local $var$1
   (get_global $gimport$2)
  )
  (set_local $var$2
   (i32.add
    (get_local $var$1)
    (get_local $var$0)
   )
  )
  (set_local $var$3
   (i32.load
    (get_local $var$2)
   )
  )
  (return
   (get_local $var$3)
  )
 )
 (func $get_foo_b (; 3 ;) (type $1) (result i32)
  (local $var$0 i32)
  (local $var$1 i32)
  (set_local $var$0
   (get_global $gimport$4)
  )
  (set_local $var$1
   (i32.load
    (get_local $var$0)
   )
  )
  (return
   (get_local $var$1)
  )
 )
 ;; custom section "dylink", size 5
 ;; custom section "producers", size 52
)

Is this intended behaviour?</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>