[llvm-bugs] [Bug 40300] New: lld-link does not detect duplicate symbols if optimizations are enabled
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Jan 13 10:46:05 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=40300
Bug ID: 40300
Summary: lld-link does not detect duplicate symbols if
optimizations are enabled
Product: lld
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: All Bugs
Assignee: unassignedbugs at nondot.org
Reporter: pavel.kryukov at phystech.edu
CC: llvm-bugs at lists.llvm.org, peter.smith at linaro.org
Hi
Consider two following simple C sources defining 'int func()'
> PS D:\Dev> cat test.c
> int func() {
> return 0;
> }
> PS D:\Dev> cat main.c
> int func() {
> return 1;
> }
>
> int main() {
> return func();
> }
lld-link.exe does not warn about duplicate symbols
> PS D:\Dev> clang-cl /O1 /c test.c
> PS D:\Dev> clang-cl /O1 /c main.c
> PS D:\Dev> lld-link test.obj main.obj
> PS D:\Dev> .\test
> PS D:\Dev> lld-link.exe --version
> LLD 7.0.0
However, if we disable optimizations, warning appears:
> PS D:\Dev> clang-cl /c main.c
> PS D:\Dev> clang-cl /c test.c
> PS D:\Dev> lld-link test.obj main.obj
> lld-link.exe: error: duplicate symbol: func in test.obj and in main.obj
MSCV linker emits a warning in both cases (sorry for the Russian output)
> PS D:\Dev> clang-cl /O1 /c test.c
> PS D:\Dev> clang-cl /O1 /c main.c
> PS D:\Dev> link test.obj main.obj
> Microsoft (R) Incremental Linker Version 14.14.26430.0
> Copyright (C) Microsoft Corporation. All rights reserved.
>
> main.obj : error LNK2005: func уже определен в test.obj
> test.exe : fatal error LNK1169: обнаружен многократно определенный символ - один или более
GCC does the same:
> PS D:\Dev> gcc test.c -O1 -c
> PS D:\Dev> gcc main.c -O1 -c
> PS D:\Dev> gcc main.c -O1 -c
> PS D:\Dev> ld test.o main.o
> main.o:main.c:(.text+0x0): multiple definition of `func'
> test.o:test.c:(.text+0x0): first defined here
> main.o:main.c:(.text+0xd): undefined reference to `__main'
--
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/20190113/24374981/attachment-0001.html>
More information about the llvm-bugs
mailing list