If we have input without object files, for example if we have only .so
code crashes in checkFlags(), getPicFlags(), getArchFlags() functions.
Patch fixes the issue.
Differential revision: https://reviews.llvm.org/D25237
llvm-svn: 283226
Previously lld would hang in infinite loop in this case,
patch fixes the issue. Object was found during AFL run.
Differential revision: https://reviews.llvm.org/D25229
llvm-svn: 283208
Relative to PR30540.
If .symtab has invalid type in elf, no bodies are created and any relocation
that tries to access them will fail.
The same can happen if symbol index is just incorrect.
This was revealed by "id_000005,sig_11,src_000000,op_flip2,pos_420"
Differential revision: https://reviews.llvm.org/D25025
llvm-svn: 283201
id_000021,sig_11,src_000002,op_flip1,pos_92 from PR30540
does not have TLS sections, but type
of one of the symbol is broken and set to STT_TLS,
what resulted in a crash. Patch fixes crash.
DIfferential revision: https://reviews.llvm.org/D25083
llvm-svn: 283198
Testcase contains a common symbol with zero alignment,
previously lld would crash, patch fixes that.
Differential revision: https://reviews.llvm.org/D25085
llvm-svn: 283197
Follow-up to r282716. Reject input files with non-zero GP0 value only in
case of relocatable object generation. In other case we can handle
arbitrary GP0 value so it does not have a sense to make the restriction
so wide.
llvm-svn: 283194
I do not fully understand how to use these classes yet, but
seems like these arguments are not used, since without them
all tests still pass. In order to simplify the situation,
I'll remove them now.
llvm-svn: 283174
Case was revealed by id_000010,sig_08,src_000000,op_havoc,rep_4 from PR30540.
Out implementation uses uint32 for storing section alignment value,
what seems reasonable, though if value exceeds 32 bits bounds we have
truncation and final value of 0.
Patch fixes the issue.
Differential revision: https://reviews.llvm.org/D25082
llvm-svn: 283097
This was intended to warn on a usage error of an ar command.
I was thinking that false positive would be rare because it
has two guards: it warns only when an archive file has no symbols
and contains at least one file.
Turned out that false positive would probably be not that rare.
You wouldn't intentionally create an object file that contains no
exported symbols, but with conditional compile guards, you could
create such file. If it is for a LTO build, you could create an
archive file containing such file. That means there's no way to
detect the usage error in a reliable manner.
This patch simply removes the warning.
llvm-svn: 282916
Previously, it warned on any archive file that has no symbol.
It turned out that that is too noisy.
With this patch, it warns on such archive file that contains no file.
Differential Revision: https://reviews.llvm.org/D25111
llvm-svn: 282885
We would crash when a non-alloca section pointed to a gced part of a
merge section.
That can happen when a C/c++ constant in put in a merge section and
debug info is present.
llvm-svn: 282845
We were implicitly creating space for the headers. That is not the
behaviour of bfd, which requires the script to use SIZEOF_HEADERS. The
difference is important for scripts that don't use SIZEOF_HEADERS and
expect the first section to be at 0.
llvm-svn: 282818
Currently lld will implicitly reserve space for the headers. This is
not the case is bfd, where it is the script responsibility to use
SIZEOF_HEADERS. This means that a script not using SIZEOF_HEADERS and
expecting the address of the first section to be 0 would fail with lld.
I am fixing that is the next commit. This one just makes the tests
explicitly use SIZEOF_HEADERS to avoid the dependency on the current
behaviour.
llvm-svn: 282814
Since they end up going on the same PT_LOAD, there is no reason to
sort them. This matches bfd's behaviour and is user visible in the
placement of orphan sections.
llvm-svn: 282799
We have a few "check" functions in Error.h. All of them are to
check for an error and strip an error object if there was no error,
except "void check(Error E)", which doesn't return anything.
This patch renames it and moves it to the .cpp file where it is used.
llvm-svn: 282764
If there is not sufficient address space, just give up and don't put
the header in the PT_LOAD.
This matches bfd behaviour and I found at least one script that
depends on having a section at address 0.
llvm-svn: 282750
LLD does not update relocations addends when generate a relocatable
object. That is why we should not write a non-zero GP0 value into
the .reginfo and .MIPS.options sections. And we should not accept input
object files with non-zero GP0 value because we cannot handle them
properly.
llvm-svn: 282716
In case of linking PIC and non-PIC code together and generation of a
relocatable object, all PIC symbols should have STO_MIPS_PIC flag in the
symbol table of the ouput file.
llvm-svn: 282714
If we two sections reside in the same PT_LOAD segment,
we compute second section using the following formula:
Off2 = Off1 + VA2 - VA1. This allows OS kernel allocating
sections correctly when loading an image.
Differential revision: https://reviews.llvm.org/D25014
llvm-svn: 282705
This subfolder just like "linkerscript" subfolder keeps
testcases with invalid input. According to PR30540 it seems
we might have many new ones soon, so it is seems reasonable to
separate them from regular testcases.
Differential revision: https://reviews.llvm.org/D25010
llvm-svn: 282595
This matches the behavior of Binutils linkers. We also change the
default MaxPageSize on x86-64 to 0x1000 to preserver the current
behavior, which is the same as the behavior implemented by gold.
https://llvm.org/bugs/show_bug.cgi?id=30541
Differential Revision: https://reviews.llvm.org/D24987
llvm-svn: 282560
Handle this in the exact same way as IMAGE_REL_AMD64_SECREL
and IMAGE_REL_I386_SECREL.
Differential revision: https://reviews.llvm.org/D24608
llvm-svn: 282531
r282444 introduced new issue, sample program below
fails to link on
assert(Piece.Live);
int main() { return 0; }
clang test.cpp -c -o out.o -g
ld.lld -flavor gnu --gc-sections out.o -o out
Problem is that .debug_info contains relocations to .debug_str:
Section (7) .rela.debug_info {
..
0xC R_X86_64_32 .debug_str 0x0
0x12 R_X86_64_32 .debug_str 0x37
..
But we do not preserve .debug_str in a right way now.
To fix this we should ignore relocations from non-allocatable sections to allocatable
to allow GC work at full power, but still should proccess relocations from non-allocatable to non-allocatable sections
as usual to mark some parts of debug sections alive to keep them so we do not end
up with such assert when trying to access dead pieces. That looks like what gold/ld do, they do
not strip .debug_str section from what I saw using sample provided.
Thanks to Evgeny Leviant for suggestions about how to fix this.
Differential revision: https://reviews.llvm.org/D24967
llvm-svn: 282495
So that it is clear that FileOutputBuffer does not depend on
PDB file builder. Eventually we will have to to get the file size
info from the file builder to create a file with the exact size.
NFC.
llvm-svn: 282454
The BYTE, SHORT, LONG, and QUAD commands store one, two, four, and eight bytes (respectively).
After storing the bytes, the location counter is incremented by the number of bytes
stored.
Previously our scripts handles these commands incorrectly. For example:
SECTIONS {
.foo : {
*(.foo.1)
BYTE(0x11)
...
We accepted the script above treating BYTE as input section description.
These commands are used in the wild though.
Differential revision: https://reviews.llvm.org/D24830
llvm-svn: 282429
PR30521 was about linking shared library. After r282295 code when linking -shared produced
"entry symbol not found" warning, what in combination with --fatal-errors failed linkage.
Patch fixes logic (and adds testcases) to follow next rules:
1) If entry was specified and not found report warning.
2) If entry was not specified then:
a) Emit warning if not -shared.
b) Do not emit warning if -shared.
Differential revision: https://reviews.llvm.org/D24913
llvm-svn: 282427
I found out this wasn't tested when looking at Vedant's coverage bot
numbers, so, thanks to him. While I'm here, switch the error message
to be lld-compliant (first letter lowercase).
llvm-svn: 282335
We were counting the size of the bss section holding common symbols twice:
Dot += CurOutSec->getSize();
flush();
The new code is also simpler as now flush is the only function that
inserts in AlreadyOutputOS, which makes sense since the set hold fully
output sections.
llvm-svn: 282285
If we pass --gc-sections to lld and .tbss is not referenced,
the section is reclaimed and lld doesn't create a TLS program header.
R_TLS tries to access the program header -> lld crashes.
Mimic what bfd/gold do in this case and resolve a weak undefined
TLS symbol to the base of the TLS block, i.e. give it a value of zero.
Differential Revision: https://reviews.llvm.org/D24832
llvm-svn: 282279
It would fail for example if the directory contained an @. Both gold
and bfd require quotes for @, so just change the test to quote the
directory name.
Thanks to Vedant Kumar for the bug report.
llvm-svn: 282256
The ARM TLS relocations are placed on literal data and not the
code-sequence, it is therefore not possible to implement the relaxTls*
functions. This change updates handleMipsTlsRelocation() to
handleNoRelaxTlsRelocation() and incorporates ARM as well as Mips.
The ARM support in handleNoRelaxTlsRelocation() currently needs to ouput
the module index dynamic relocation in all cases as it is relying on the
dynamic linker to set the module index in the got.
Should address PR30218
Differential Revision: https://reviews.llvm.org/D24827
llvm-svn: 282250
Previously we failed to parse next scripts because disallowed
a space between filler value and '=':
.text : {
...
} :text = 0x9090
Differential revision: https://reviews.llvm.org/D24831
llvm-svn: 282248
DEFINED(symbol)
Return 1 if symbol is in the linker global symbol table and is defined before
the statement using DEFINED in the script, otherwise return 0.
Can be used to define default values for symbols. Found it in the wild.
Differential revision: https://reviews.llvm.org/D24858
llvm-svn: 282245
If section contains local symbols ldd crashes, because local
symbols are added to symbol table before section is discarded
by linker script processor. This patch calls copyLocalSymbols()
after createSections, so discarded section symbols are not copied
llvm-svn: 282244
Found this operators used in the wild scripts, for example:
__got2_entries = (_FIXUP_TABLE_ - _GOT2_TABLE_) >>2;
__fixup_entries = (. - _FIXUP_TABLE_)>>2;
Differential revision: https://reviews.llvm.org/D24860
llvm-svn: 282243
The ELF spec doesn't allow relocations to point directly to
a deduplicated COMDAT section but this unfortunately happens in
practice. Bail out early instead of crashing.
Differential Revision: https://reviews.llvm.org/D24750
llvm-svn: 282197
With the recent changes there should always be a 1:1 correspondence in
the correct order between OutputSections and OutputSectionCommands.
llvm-svn: 282176
The actual logic is to keep the output section if the output section
would have been ro/rw.
This is both simpler and more practical, as the intention is linker
scripts is to always keep of of a pair of ONLY_IF_RO/ONLY_IF_RW.
llvm-svn: 282099
This is PR30442.
Previously we were failed to parce complex expressions like:
foo : { *(SORT_BY_NAME(bar) zed) }
Main idea of patch that globs and excludes can be wrapped in a SORT.
There is a difference in semanics of ld/gold:
ld likes:
*(SORT(EXCLUDE_FILE (*file1.o) .foo.1))
gold likes:
*(EXCLUDE_FILE (*file1.o) SORT(.foo.1))
Patch implements ld grammar, complex expressions like
next is not a problem anymore:
.abc : { *(SORT(.foo.* EXCLUDE_FILE (*file1.o) .bar.*) .bar.*) }
Differential revision: https://reviews.llvm.org/D24758
llvm-svn: 282078
When final image has several .bss sections, lld fails
because second .bss always has zero VA. This causes
link error "Not enough space for ELF and program headers"
llvm-svn: 282067