<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 - lld-link does not detect duplicate symbols if optimizations are enabled"
href="https://bugs.llvm.org/show_bug.cgi?id=40300">40300</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>lld-link does not detect duplicate symbols if optimizations are enabled
</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>Windows NT
</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>pavel.kryukov@phystech.edu
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, peter.smith@linaro.org
</td>
</tr></table>
<p>
<div>
<pre>Hi
Consider two following simple C sources defining 'int func()'
<span class="quote">> PS D:\Dev> cat test.c
> int func() {
> return 0;
> }
> PS D:\Dev> cat main.c
> int func() {
> return 1;
> }
>
> int main() {
> return func();
> }</span >
lld-link.exe does not warn about duplicate symbols
<span class="quote">> 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</span >
However, if we disable optimizations, warning appears:
<span class="quote">> 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</span >
MSCV linker emits a warning in both cases (sorry for the Russian output)
<span class="quote">> 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: обнаружен многократно определенный символ - один или более</span >
GCC does the same:
<span class="quote">> 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'</span ></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>