<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 - symbol defined in linker script populated with incorrect address"
href="https://bugs.llvm.org/show_bug.cgi?id=32331">32331</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>symbol defined in linker script populated with incorrect address
</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>ELF
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>superjoe30@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=18122" name="attach_18122" title="main.ll">attachment 18122</a> <a href="attachment.cgi?id=18122&action=edit" title="main.ll">[details]</a></span>
main.ll
Using the below linker script, the attached LLVM IR module, and the below LLD
invocation, the symbol __bss_end gets the address 0x547 instead of 0xad54 as
expected.
clang -o clashos.o -c main.ll
ld.lld -T linker.ld --gc-sections -m armelf_linux_eabi -Bstatic -o clashos
clashos.o memset.o memcpy.o compiler_rt.o
linker.ld:
ENTRY(_start)
SECTIONS {
. = 0x8000;
.text : ALIGN(4K) {
KEEP(*(.text.boot))
*(.text)
}
.rodata : ALIGN(4K) {
*(.rodata)
}
.data : ALIGN(4K) {
*(.data)
}
__bss_start = .;
.bss : ALIGN(4K) {
*(COMMON)
*(.bss)
}
__bss_end = .;
}
What appears to be happening is that __bss_end is equal to __bss_start, because
there are no .bss section global variables. Using GNU binutils ld, __bss_start
and __bss_end both get the same address, as expected. With LLD, __bss_end gets
an address that is less than __bss_start, which is unexpected, and causes an
integer overflow in code that expects to be able to do __bss_end - __bss_start
to get the size of the .bss section.
When I add a global variable that goes in the .bss section, LLD then correctly
sets __bss_end.</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>