Issue 244540
Summary [MC] Difference involving weak symbol incorrect folded at assembly time
Labels miscompilation, llvm:binary-utilities, mc
Assignees
Reporter nikic
    ```asm
 .section .rodata,"a",@progbits
        .weak   a
        .p2align 2
a:    
        .long   42

        .globl  table
table:
        .long a - table
```

```
build/bin/llvm-mc -filetype=obj test.s -o test.o
llvm-readelf -r test.o
llvm-objdump -s -j .rodata test.o
```
Gives:
```
There are no relocations in this file.

Contents of section .rodata:
 0000 2a000000 fcffffff *.......
```

So the assembler is implicitly assuming that the weak definition we see is the prevailing definition, which is obviously incorrect. GNU `as` behaves the same way.

Apparently, this behavior was introduced intentionally in https://github.com/llvm/llvm-project/commit/35d6189f0fc2bbb103846ffaac4b3e0043607885, because some debuginfo functionality would fail to assemble otherwise. The referenced issues are https://github.com/llvm/llvm-project/issues/23646 and https://github.com/llvm/llvm-project/issues/23189.

However, this does mean that we cannot use relative lookup tables involving weak symbols (or probably more relevantly, linkonce_odr symbols).
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to