Commit Graph

6773 Commits

Author SHA1 Message Date
Rui Ueyama 9c4ac5f26c Combine two StringSwitch::Cases because Cases now can take 6 parameters.
llvm-svn: 282307
2016-09-23 22:22:34 +00:00
Rafael Espindola 251e240adc Warn if we can't find the entry symbol.
Fixes pr30465.

llvm-svn: 282295
2016-09-23 21:04:56 +00:00
Rafael Espindola 65499b9040 Avoid counting sections twice.
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
2016-09-23 20:10:47 +00:00
Davide Italiano 03f7005375 [ELF] Resolve weak undefined TLS symbols when no phdr is available.
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
2016-09-23 18:47:50 +00:00
Rui Ueyama 0120e3f278 Simplify. NFC.
llvm-svn: 282268
2016-09-23 18:06:51 +00:00
Rafael Espindola cfdd1fdfb6 Fix test when run in unusual test directories.
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
2016-09-23 15:34:53 +00:00
Peter Smith fde6213fe8 [ARM] ARM TLS shouldn't use relaxations
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
2016-09-23 13:54:48 +00:00
George Rimar 4ebc562052 [ELF] - Linkerscript: accept space between '=' and expression in section filler.
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
2016-09-23 13:29:20 +00:00
George Rimar f34f45fd53 [ELF] - Linkerscript: implement DEFINED() command.
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
2016-09-23 13:17:23 +00:00
Eugene Leviant d4dea164dd Linker script: fix crash when discarding section
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
2016-09-23 13:17:16 +00:00
George Rimar c8ccd1f1c5 [ELF] - Linkerscript: Implemented >> and <<
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
2016-09-23 13:13:55 +00:00
Davide Italiano 49ab2517f5 [ELF/GC] Don't crash while processing Discarded sections.
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
2016-09-22 21:08:51 +00:00
Vedant Kumar 387eb83a50 [lld] Add llvm-pdbdump as a test dependency
Reviewed-by: rafael
llvm-svn: 282187
2016-09-22 20:12:23 +00:00
Rafael Espindola 29c59cc15d Remove extra \
Should fix the windows bots.

llvm-svn: 282181
2016-09-22 18:36:46 +00:00
Rafael Espindola 15c579518d Don't move orphan sections past assignments.
This fixes a case where we would produce an unaligned PT_LOAD.

llvm-svn: 282180
2016-09-22 18:05:49 +00:00
Rafael Espindola 1998ee53f0 Simplify. NFC.
With the recent changes there should always be a 1:1 correspondence in
the correct order between OutputSections and OutputSectionCommands.

llvm-svn: 282176
2016-09-22 17:23:53 +00:00
Rafael Espindola 0d4b6d5c98 Avoid duplicated code.
This also fixes the linker script accounting for the ELF header in
some places but not in others.

llvm-svn: 282173
2016-09-22 16:47:21 +00:00
Rafael Espindola 2644208381 Simplify. NFC.
It doesn't matter which direction we rotate and we haven't really
started optimizing the linker script code, so keep this simple.

llvm-svn: 282166
2016-09-22 15:25:21 +00:00
Rafael Espindola 9546fffbfe Handle empty sections with symbol assignments.
Before the symbols were becoming undefined.

llvm-svn: 282159
2016-09-22 14:40:50 +00:00
Rafael Espindola a940e5396b Fix VA computation for tbss.
llvm-svn: 282149
2016-09-22 12:35:44 +00:00
Rafael Espindola 7252ae52cf Handle multiple .tbss sections.
llvm-svn: 282147
2016-09-22 12:00:08 +00:00
Rafael Espindola 24c073d1bb Once more unto the strict weak ordering, once more.
This should finally give a stable sorting over all implementations.

llvm-svn: 282118
2016-09-21 22:36:19 +00:00
Rafael Espindola e746e52c7b Implement ONLY_IF_RO/ONLY_IF_RW like bfd.
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
2016-09-21 18:33:44 +00:00
George Rimar 07171f21d1 [ELF] - Linkerscript: support complex section pattern grammar.
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
2016-09-21 15:56:44 +00:00
Eugene Leviant 2506cb4ddb Linker script: Fix bug with several .bss
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
2016-09-21 11:29:28 +00:00
George Rimar 601e989879 [ELF] - Linkerscript: reimplement readSectionExcludes()
It is not only a bit more straightforward now, but also next 2 issues are solved:

* It just crashed on ".foo : { *(EXCLUDE_FILE (*file1.o)) }" before.
* It accepted multiple EXCLUDE_FILEs in a row.

Differential revision: https://reviews.llvm.org/D24726

llvm-svn: 282060
2016-09-21 08:53:21 +00:00
Rui Ueyama c75ef85e84 Accept sh_entsize = 0.
This surfaced again with Rust. As per bug 30435, rustc creates a
mergeable section with a sh_entsize zero. It bit us before, too.
I think we should relax the input check rather than being too picky.

Differential Revision: https://reviews.llvm.org/D24789

llvm-svn: 282049
2016-09-21 03:22:18 +00:00
Rafael Espindola b6b8f6c308 Revert "Revert "Only restrict order if both sections are in the script.""
This reverts commit r282021, bringing back r282015.

The problem was that the comparison function was not a strict weak
ordering anymore, which this patch fixes.

Original message:

Only restrict order if both sections are in the script.

This matches gold and bfd behavior and is required to handle some scripts.

The script has to assume where PT_LOADs start in order to align that
spot. If we don't allow section it doesn't know about to move to the
middle, we can need more PT_LOADs and those will not be aligned.

llvm-svn: 282035
2016-09-20 22:43:15 +00:00
Rafael Espindola bf04708e11 Revert "Only restrict order if both sections are in the script."
This reverts commit r282015. It broke some bots.

llvm-svn: 282021
2016-09-20 21:28:19 +00:00
Rafael Espindola 145569df64 Only restrict order if both sections are in the script.
This matches gold and bfd behavior and is required to handle some scripts.

The script has to assume where PT_LOADs start in order to align that
spot. If we don't allow section it doesn't know about to move to the
middle, we can need more PT_LOADs and those will not be aligned.

llvm-svn: 282015
2016-09-20 20:54:39 +00:00
Rafael Espindola e5bfa690d0 Make test less dependent on the section order.
This means either relaxing CHECKs or listing more sections and
addresses in linker scripts.

llvm-svn: 282014
2016-09-20 20:48:54 +00:00
Rui Ueyama ee92470969 Simplify SORT and --sort-section command line option handling.
Differential Revision: https://reviews.llvm.org/D24685

llvm-svn: 282006
2016-09-20 19:42:41 +00:00
Rafael Espindola db62cbb97f Don't produce an error for undefined entry symbol.
This is particularly important when the symbol comes from a linker
script. It is common to use the same linker script for shared
libraries and executables. Without this we would always fail to link
shared libraries with -z,defs and a linker script with an ENTRY
directive.

llvm-svn: 281989
2016-09-20 17:14:16 +00:00
Rafael Espindola c8e7c98b66 Redirect stderr to /dev/null. NFC.
Makes the error output less confusing when this test fails.

llvm-svn: 281985
2016-09-20 17:02:38 +00:00
Davide Italiano 8f41f33f45 [Writer] Fix a typo. NFC.
llvm-svn: 281984
2016-09-20 16:57:02 +00:00
Rafael Espindola b45fd70ef1 Disable --rosegment when we have linker scripts.
Linker scripts are responsible for aliging '.'. Since they are
designed for bfd which has no --rosegment, they don't align the RO to
RX transition.

llvm-svn: 281978
2016-09-20 15:22:27 +00:00
Rafael Espindola 1b87995f31 Make tests less dependent on the exact layout.
In most cases that means just not checking the address when we don't
need it.

For some tests it is easier to just set . to a known value.

llvm-svn: 281976
2016-09-20 15:08:24 +00:00
Rafael Espindola 49913bc63d Move test to the correct directory. NFC.
llvm-svn: 281974
2016-09-20 14:49:18 +00:00
Rafael Espindola 6d38e4dbe1 Remove empty section commands.
We were already not creating them, and with this other parts of the
code don't have to worry about them.

llvm-svn: 281968
2016-09-20 13:12:07 +00:00
Rui Ueyama d1d7cfcd52 Remove a use of std::list.
llvm-svn: 281951
2016-09-20 00:02:06 +00:00
Davide Italiano 1c3c3953c6 [GC] Don't crash when printing the special Discarded GC section.
InputSection<ELFT>::Discarded has no name and it's not backed by
a file. Trying to report it as discared will cause a nullptr
dereference, therefore a crash. Skip it.

Differential Revision:   https://reviews.llvm.org/D24731

llvm-svn: 281946
2016-09-19 23:15:51 +00:00
Rafael Espindola caa6024303 Use FileCheck variables. NFC.
llvm-svn: 281932
2016-09-19 20:23:19 +00:00
Rafael Espindola 7d38273636 Map .data.rel.ro correctly.
An input section named .data.rel.ro now maps to an output section
named .data.rel.ro. Before we were mapping it to .data.

llvm-svn: 281931
2016-09-19 19:59:21 +00:00
Rafael Espindola 3d90318aff Make this test a bit stricter.
By making every section on byte and checking the size it now shows how
many sections were concatenated into each output section.

llvm-svn: 281930
2016-09-19 19:56:51 +00:00
Rafael Espindola 881f12ee0b Don't CHECK the addresses. NFC
That is not what this test is about. This reduces changes in another
patch that changes layout.

llvm-svn: 281929
2016-09-19 18:58:30 +00:00
Davide Italiano 6f862b1f07 [Writer] Rename variables to reflect reality. NFCI.
The InputSection variables in the Writer were named `C`. This
was because when the ELF linker was ported (from COFF)
the name `Chunks` for input sections was retained.
Luckily we switched to a more ELF-compliant jargon, but these
variables weren't reanamed accordingly during the transition.

llvm-svn: 281917
2016-09-19 17:38:39 +00:00
Rafael Espindola f135f0ec1d Remove unnecessary const_canst. NFC.
llvm-svn: 281901
2016-09-19 13:33:38 +00:00
George Rimar b31dd37005 [ELF] - LinkerScript: Add workaround for gcc 6.2.0 failure w/auto
Will Dietz found and reported that lld does not compile with gcc 6.2.0,
more details https://llvm.org/bugs/show_bug.cgi?id=30438

And confirmed this change fixes the issue.

llvm-svn: 281900
2016-09-19 13:27:31 +00:00
George Rimar 194470cd11 [ELF] - Fix comment. NFC.
llvm-svn: 281836
2016-09-17 19:21:05 +00:00
George Rimar af03be19f9 [ELF] - Added comments. NFC.
llvm-svn: 281835
2016-09-17 19:17:25 +00:00