Commit Graph

6863 Commits

Author SHA1 Message Date
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
George Rimar 331b9ae196 [ELF] - Linkerscript: change locationcounter.s to use llvm-objdump
Previously it used llvm-readobj -s, now changed to llvm-objdump -section-headers,
that reduced the output significantly and helps to read/support it.

llvm-svn: 281832
2016-09-17 18:35:24 +00:00
George Rimar 8c658bf824 [ELF] - SEGMENT_START's default argument can be an expression
Our implementation supported integer value previously.
ld can use expression,
for example, it is OK to write
 . = SEGMENT_START("foobar", .);

Patch implements that.

llvm-svn: 281831
2016-09-17 18:14:56 +00:00
George Rimar dfbbbc86a1 [ELF] Linkerscript: fixed bug about commands processing.
It was possible situation about some commands just were not processed
(were skipped) because of a bug appeared when constraint checking used.

Testcase is attached.

llvm-svn: 281818
2016-09-17 09:50:10 +00:00
George Rimar 8034d49db5 [ELF] - Fixed mistypes in comments. NFC.
llvm-svn: 281817
2016-09-17 07:31:49 +00:00
Rui Ueyama 70efa2f251 Attempt to fix buildbot.
llvm-svn: 281805
2016-09-17 02:34:50 +00:00
Rui Ueyama 4dc07becd0 Use named struct instead of unnamed std::pair.
It is important to give members names for readability.

llvm-svn: 281803
2016-09-17 02:23:40 +00:00
Rui Ueyama 3ff27f49cd Define a versatile utility function and use it instead of a single purpose one.
llvm-svn: 281802
2016-09-17 02:15:28 +00:00
Rui Ueyama 027a9e8787 Remove unnecessary namespace specifiers.
llvm-svn: 281801
2016-09-17 02:10:15 +00:00
Rui Ueyama bb542b3f0c Partially fill Info stream with proper values.
llvm-svn: 281795
2016-09-16 22:51:17 +00:00
Rafael Espindola 373343bd5b Try to fix a few bots.
llvm-svn: 281794
2016-09-16 22:47:34 +00:00
Rafael Espindola aab6d5c52a Put SHF_ALLOC sections first, even with linker scripts.
This matches gold and bfd, and is pretty much required by some linker
scripts. They end with commands like

foo   0 : { *(bar) }

if we put any SHF_ALLOC sections after they can have an address that
is too low.

llvm-svn: 281778
2016-09-16 21:29:07 +00:00
Rui Ueyama b2a0abdf0e Rename SortSectionPolicy::IgnoreConfig to None.
Because it corresponds to SORT_NONE. None was renamed Default.

llvm-svn: 281776
2016-09-16 21:14:55 +00:00
Rafael Espindola 7c3ff2eb58 Only process commands in a ONLY_IF_RO if it matches.
This matches bfd behavior. It also makes future changes simpler as we
don't have to worry about ignoring these commands in multiple places

llvm-svn: 281775
2016-09-16 21:05:36 +00:00
Rafael Espindola e71a3f8ae1 Fix constraint checking in ONLY_IF_RO.
We have to look at all the relevant input sections at once.

llvm-svn: 281772
2016-09-16 20:34:02 +00:00
George Rimar be394db376 [ELF] - Implemented --sort-section cmd line option and SORT_NONE script command.
This fixes Bug 30385 - SORT_NONE not implemented,

`SORT_NONE' disables section sorting by ignoring the command line
section sorting option.

That is why this patch also implements --sort-section option.

Description of sorting rules
available at https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html 

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

llvm-svn: 281771
2016-09-16 20:21:55 +00:00
George Rimar 395281cfc3 Recommit r281721 "[ELF] - Linkerscript: implement EXCLUDE_FILE in the middle of a input section description."
With fix for 2 bots. Details about the fix performed is on a review page.

Initial commit message:
This is PR30387:

From PR description:
We fail to parse

SECTIONS
{
  foo :
  {
    *(sec0 EXCLUDE_FILE (zed1.o) sec1  EXCLUDE_FILE (zed2.o) sec2 )
  }
}
The semantics according to bfd are:

Include sec1 from every file but zed1.o
Include sec2 from every file but zed2.o
Include sec0 from every file

Patch implements the support.

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

llvm-svn: 281754
2016-09-16 17:42:10 +00:00
Eugene Leviant 20d031948e Improve handling ASSERT outside SECTIONS block
Differential revision: https://reviews.llvm.org/D24450

llvm-svn: 281740
2016-09-16 15:30:47 +00:00
Rafael Espindola d31907957a Change how we compute offsets with linker scripts.
This fixes pr30367, but more importantly, it changes how we compute offsets.

Now offset computation in a walk over linker script commands, like the
rest of assignAddresses. IMHO this is simpler to understand and if we
ever have to create multiple outputsections or chunks to change how we
handle test/ELF/linkerscript/alternate-sections.s it should be easier
to do it.

llvm-svn: 281736
2016-09-16 15:10:23 +00:00
Ismail Donmez e7174ffcd8 Fix shared library build
llvm-svn: 281728
2016-09-16 14:10:23 +00:00
George Rimar ceae630c9b Reverted r281721 ("[ELF] - Linkerscript: implement EXCLUDE_FILE in the middle of a input section description.").
It broke build bot:
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/27508

llvm-svn: 281723
2016-09-16 13:30:18 +00:00
George Rimar 4906c7f5c4 [ELF] - Linkerscript: implement EXCLUDE_FILE in the middle of a input section description.
This is PR30387:

From PR description:
We fail to parse

SECTIONS
{
  foo :
  {
    *(sec0 EXCLUDE_FILE (zed1.o) sec1  EXCLUDE_FILE (zed2.o) sec2 )
  }
}
The semantics according to bfd are:

Include sec1 from every file but zed1.o
Include sec2 from every file but zed2.o
Include sec0 from every file

Patch implements the support.

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

llvm-svn: 281721
2016-09-16 13:07:02 +00:00
Rui Ueyama b28c6d495d Use functions in DebugInfoPDB to create dummy PDB file.
I don't think we are creating valid PDB file here,
but it is okay because we have never created valid PDBs before.

llvm-svn: 281704
2016-09-16 04:32:33 +00:00
Rui Ueyama 2644cd1d88 Demangle symbols in "undefined symbol" error message.
llvm-svn: 281698
2016-09-16 03:52:45 +00:00
Rui Ueyama 783afd667d Check /pdb output using llvm-pdbdump.
test/COFF/rsds.test checks only RSDS directory in a DLL and
didn't check the validity of the PDF file produced.
(Technically the produced PDB is not valid because it is really
a stub, but this test is still good to have.)

llvm-svn: 281678
2016-09-15 23:14:40 +00:00
Rui Ueyama 8e8296fad8 Fix old copy-n-paste errors.
llvm-svn: 281671
2016-09-15 22:26:07 +00:00
Rui Ueyama 1d99ab3925 Create PDB.h and move code to remove unnecessary #includes.
llvm-svn: 281670
2016-09-15 22:24:51 +00:00
Rafael Espindola 4ec013ac83 Error out instead of producing a corrupt PT_LOAD.
What bfd and gold do is give up in putting the headers in the PT_LOAD
and just start the PT_LOAD in the second page.

llvm-svn: 281660
2016-09-15 21:22:11 +00:00
Rafael Espindola 1d98d6292f Make sure we create all necessary PT_LOADs.
We were some times stopping early when using linker scripts.

llvm-svn: 281647
2016-09-15 19:36:01 +00:00
George Rimar 575208cabd [ELF] - Linkerscript: implemented SORT_BY_INIT_PRIORITY.
This is PR30386,

SORT_BY_INIT_PRIORITY is a keyword can be used to sort sections by numerical value of the
GCC init_priority attribute encoded in the section name.

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

llvm-svn: 281646
2016-09-15 19:15:12 +00:00
Rui Ueyama 7f38299919 Use SuperBlock struct defined in MSFCommon.h.
llvm-svn: 281643
2016-09-15 18:55:18 +00:00
Rafael Espindola 3adbbc3891 Check the return of getInteger.
llvm-svn: 281608
2016-09-15 13:36:44 +00:00
George Rimar 31c25ae90a Recommit r281318 "[ELF] - Versionscript: support mangled symbols with the same name."
Previouly bot was failing:
http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/413/steps/test-stage1-compiler/logs/stdio
Fixed possible segfault, so commit should bix the buildbot.

Initial commit message:

This is PR30312. Info from bug page:

Both of these symbols demangle to abc::abc():
_ZN3abcC1Ev
_ZN3abcC2Ev
(These would be abc's complete object constructor and base object constructor, respectively.)
however with "abc::abc()" in the version script only one of the two receives the symbol version.

Patch fixes that.
It uses testcase created by Ed Maste (D24306).

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

llvm-svn: 281605
2016-09-15 12:44:38 +00:00
Rafael Espindola 97bdc7220b Handle arbitrary expressions in DATA_SEGMENT_RELRO_END.
llvm-svn: 281521
2016-09-14 19:14:01 +00:00
Rafael Espindola 0289c5bbcd Add an interesting test.
llvm-svn: 281515
2016-09-14 18:06:02 +00:00
Rafael Espindola 77af7e48b7 Add a test showing we handle .tbss sections in linker scripts.
llvm-svn: 281496
2016-09-14 16:40:33 +00:00
Simon Atanasyan d10a5ea19e [ELF] Do not adjust TLS symbol value when produce relocatable object
When the linker generates a relocatable object there is no TLS program
header and we should not adjust TLS symbols value.

llvm-svn: 281494
2016-09-14 16:26:19 +00:00
Rafael Espindola be94e1b630 Move helper function higher in the file. NFC
This just makes a followup patch easier to read.

llvm-svn: 281482
2016-09-14 14:32:08 +00:00
George Rimar d73ef1738b [ELF] - Implemented --section-start, -Ttext, -Tdata, -Tbss options.
--section-start=sectionname=org
Locate a section in the output file at the absolute address given by org. 
You may use this option as many times as necessary to locate multiple sections in the command line.
 org must be a single hexadecimal integer; for compatibility with other linkers, 
you may omit the leading `0x' usually associated with hexadecimal values. 
Note: there should be no white space between sectionname, the equals sign (“<=>”), and org.

-Tbss=org
-Tdata=org
-Ttext=org
Same as --section-start, with .bss, .data or .text as the sectionname.

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

llvm-svn: 281458
2016-09-14 13:07:13 +00:00
Rafael Espindola d88d7166a8 Use murmurhash2 instead of fnv.
It is substantially faster by processing 8 bytes at a time.

llvm-svn: 281454
2016-09-14 11:32:57 +00:00
Eugene Leviant e05336ffa1 [ELF] Replace HasContents with HasSections. NFC
llvm-svn: 281449
2016-09-14 08:32:36 +00:00
Rui Ueyama 2d7fe598f2 Turn a no-op assignment into an assertion.
r279456 guarantees that this condition is always satisfied.

llvm-svn: 281426
2016-09-14 00:09:50 +00:00
Rui Ueyama 38dbd3eea9 Simplify InputFile ownership management.
Previously, all input files were owned by the symbol table.
Files were created at various places, such as the Driver, the lazy
symbols, or the bitcode compiler, and the ownership of new files
was transferred to the symbol table using std::unique_ptr.
All input files were then free'd when the symbol table is freed
which is on program exit.

I think we don't have to transfer ownership just to free all
instance at once on exit.

In this patch, all instances are automatically collected to a
vector and freed on exit. In this way, we no longer have to
use std::unique_ptr.

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

llvm-svn: 281425
2016-09-14 00:05:51 +00:00
George Rimar 84ba4ae11d revert: [ELF] - Versionscript: support mangled symbols with the same name.
Something broked BBots:
281318 failed on step 9:
http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/413

r281317 built step 9 green:
http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/415

Initial revision commits were:
This is PR30312. Info from bug page:

Both of these symbols demangle to abc::abc():
_ZN3abcC1Ev
_ZN3abcC2Ev
(These would be abc's complete object constructor and base object constructor, respectively.)
however with "abc::abc()" in the version script only one of the two receives the symbol version.

Patch fixes that.
It uses testcase created by Ed Maste (D24306).

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

llvm-svn: 281411
2016-09-13 22:26:12 +00:00
Rui Ueyama 1e2e8eae5d [ELF] Set EF_ARM_EABI_VER5 for ARM
Without this flag set, an AArch64 Linux kernel won't try to load the executable
(even if a 32 bit arm kernel will run the binary just fine).

Patch by Martin Storsjö!

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

llvm-svn: 281394
2016-09-13 20:51:32 +00:00
Rui Ueyama ea26504c19 Split scanVersionScript. NFC.
llvm-svn: 281393
2016-09-13 20:51:30 +00:00
Rui Ueyama fbde710497 Add comments.
llvm-svn: 281388
2016-09-13 20:41:06 +00:00
Rui Ueyama 3e9037d419 Inline small funciton.
llvm-svn: 281381
2016-09-13 19:56:27 +00:00
Rui Ueyama a75b7a48f1 Fix comments.
llvm-svn: 281380
2016-09-13 19:56:25 +00:00
Rafael Espindola 10897f1807 Enable merging of SHF_MERGE sections with linker scripts.
This also fixes the related problem of non SHF_MERGE sections with
different flags not being merged.

Fixes pr30355.

llvm-svn: 281338
2016-09-13 14:23:14 +00:00
Rafael Espindola 28c1597ad9 Refactor duplicated code. NFC.
llvm-svn: 281329
2016-09-13 13:00:06 +00:00
Rafael Espindola 17c35832a0 Turn createKey into a static helper. NFC.
llvm-svn: 281325
2016-09-13 12:25:30 +00:00
Rafael Espindola 540893a2e2 Delete dead code.
We already handle this is createSections.

llvm-svn: 281320
2016-09-13 11:28:22 +00:00
George Rimar e2051efcbe [ELF] - Versionscript: support mangled symbols with the same name.
This is PR30312. Info from bug page:

Both of these symbols demangle to abc::abc():
_ZN3abcC1Ev
_ZN3abcC2Ev
(These would be abc's complete object constructor and base object constructor, respectively.)
however with "abc::abc()" in the version script only one of the two receives the symbol version.

Patch fixes that.
It uses testcase created by Ed Maste (D24306).

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

llvm-svn: 281318
2016-09-13 10:45:39 +00:00
Chris Bieneman 5a805df1a5 [CMake] Fix linker-as-ld to symlink instead of copy lld
Summary: This test fails if you're building with BUILD_SHARED_LIBS because the LLVM libraries are found via @rpath. Symlinking instead of copying should be sufficiently robust for the test case.

Reviewers: llvm-commits

Subscribers: davide

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

llvm-svn: 281271
2016-09-12 22:38:43 +00:00
Rui Ueyama 0eb2a1bd7a Add comments.
llvm-svn: 281265
2016-09-12 21:44:29 +00:00
Davide Italiano f6c1d2c158 [MachO] Factor out a fair amount of duplicated code. NFCI.
llvm-svn: 281260
2016-09-12 21:07:26 +00:00
Davide Italiano 3582242aa3 [Cmake] Use Cmake's default RPATH for unittest.
Similarly to what was done in r280791 for llvm/.
This should fix a bunch of failures I saw while
trying a BUILD_SHARED_LIBS build on MacOS.
Still there are some failures, but this is a step
forward.

Thanks a lot to Chris Bieneman for the suggested
fix (in PR30345)

llvm-svn: 281256
2016-09-12 20:44:53 +00:00
Rafael Espindola 7bd37870bc Simplify handling of /DISCARD/. NFC.
llvm-svn: 281222
2016-09-12 16:05:16 +00:00
Rafael Espindola c7e1e03498 Store an ArrayRef for Data in InputSectionData.
llvm-svn: 281210
2016-09-12 13:13:53 +00:00
Rafael Espindola 54f1614ec1 Revert "Revert "Compact InputSectionData from 64 to 48 bytes. NFC.""
This reverts commit r281096.

The previous link errors should be fixed by r281208.

llvm-svn: 281209
2016-09-12 13:06:10 +00:00
Eugene Leviant 99da752980 [ELF/AArch64] Implement some UABS relocs
Differential revision: https://reviews.llvm.org/D24403

llvm-svn: 281202
2016-09-12 10:02:41 +00:00
Davide Italiano 35065193f1 [MachO] Remove code accidentally cut'n'pasted 3 times.
It wasn't harmful, just goofy. It's weird to see how this has
fallen through the crack without anybody noticing for so long.

llvm-svn: 281148
2016-09-10 20:41:26 +00:00
Michael J. Spencer 0cb8a70adc [ELF] Fix memory leak in BinaryFile handling.
llvm-svn: 281129
2016-09-10 01:42:43 +00:00
Hans Wennborg efcc5c4390 Move the contents of test/elf to test/ELF
Having two directories with the same name modulo case does not work well
on Windows. The new test/elf directory was added in r281108. I assume
the intention was to add the test file to the existing test/ELF dir.

llvm-svn: 281115
2016-09-09 22:46:16 +00:00
Michael J. Spencer a9424f39c4 [ELF] Add support for -b binary
Implemented by building an ELF file in memory.

elf, default, and binary match gold behavior.

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

llvm-svn: 281108
2016-09-09 22:08:04 +00:00
Rui Ueyama 478f8eb6ef Add comments.
llvm-svn: 281098
2016-09-09 21:35:38 +00:00
Rafael Espindola 78fe670994 Revert "Compact InputSectionData from 64 to 48 bytes. NFC."
This reverts commit r281084.

The link was failing on some bots. No idea why. I will try to
reproduce it on Monday.

llvm-svn: 281096
2016-09-09 21:20:30 +00:00
Rafael Espindola 82621dcb10 Compact InputSectionData from 64 to 48 bytes. NFC.
llvm-svn: 281084
2016-09-09 19:42:11 +00:00
Saleem Abdulrasool c1b5f19262 test: adjust the GUID
Although the GUID seems to be stable across test runs now, it seems to be
unstable across hosts.  Lets be a bit more lax about the reading of the RSDS
record.

llvm-svn: 281083
2016-09-09 19:41:46 +00:00
Saleem Abdulrasool 88f6407542 COFF: make builds more reproducible
Change the way we calculate the build id to use MD5 to give reproducible build
ids. Previously we would generate random bytes for the build id GUID.

llvm-svn: 281079
2016-09-09 19:26:03 +00:00
George Rimar cd574a5e46 Recommit [ELF] - Versionscript: do not treat non-wildcarded names as wildcards.
Fixed code that was not checked before on windows for me, because of testcases that are
disabled on that platform atm.

Inital commit message:
"[ELF] - Versionscript: do not treat non-wildcarded names as wildcards."
Previously we incorrectly handled cases when symbol name in extern c++ tag
was enclosed in quotes. Next case was treated as wildcard:

GLIBCXX_3.4 {                                                                   
    extern "C++" {  
    "aaa*"
   }
But it should have not. Quotes around aaa here means that we should have do exact
name matching.
That is PR30268 which has name with pointer is interpreted as wildcard by lld:

extern "C++" {                                                              
    "operator delete[](void*)";

Patch fixes the issue.

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

llvm-svn: 281049
2016-09-09 14:35:36 +00:00
George Rimar 6368525eea Revert r281045, it broke BB.
Broken BB:
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/27211

llvm-svn: 281046
2016-09-09 14:16:00 +00:00
George Rimar b5e77c47fb Recommit [ELF] - Versionscript: do not treat non-wildcarded names as wildcards.
Fixed code that was not checked by testcases that are disabled on windows.

Inital commit message:
"[ELF] - Versionscript: do not treat non-wildcarded names as wildcards."
Previously we incorrectly handled cases when symbol name in extern c++ tag
was enclosed in quotes. Next case was treated as wildcard:

GLIBCXX_3.4 {                                                                   
    extern "C++" {  
    "aaa*"
   }
But it should have not. Quotes around aaa here means that we should have do exact
name matching.
That is PR30268 which has name with pointer is interpreted as wildcard by lld:

extern "C++" {                                                              
    "operator delete[](void*)";

Patch fixes the issue.

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

llvm-svn: 281045
2016-09-09 13:58:07 +00:00
George Rimar 08b1862caf [ELF] - Revert r281038 to see if that unbreaks build bot.
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/19703

llvm-svn: 281041
2016-09-09 12:56:55 +00:00
George Rimar d220384376 [ELF] - Versionscript: do not treat non-wildcarded names as wildcards.
Previously we incorrectly handled cases when symbol name in extern c++ tag
was enclosed in quotes. Next case was treated as wildcard:

GLIBCXX_3.4 {                                                                   
    extern "C++" {  
    "aaa*"
   }
But it should have not. Quotes around aaa here means that we should have do exact
name matching.
That is PR30268 which has name with pointer is interpreted as wildcard by lld:

extern "C++" {                                                              
    "operator delete[](void*)";

Patch fixes the issue.

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

llvm-svn: 281038
2016-09-09 12:22:28 +00:00
Eugene Leviant 56b21c869e Linker script: implement AT [ (address) ] for PHDR
Differential revision: https://reviews.llvm.org/D24340

llvm-svn: 281024
2016-09-09 09:46:16 +00:00
Rui Ueyama a60058c8f5 Fix -output option.
Usually, options that are longer than one character can be preceded
either by "-" or "--", but options starting with "o" are exceptions
because they conflict with "-o" option. They have to be preceded by
"--".

llvm-svn: 281004
2016-09-09 00:25:56 +00:00
Rui Ueyama 86c5fb8296 Fix bug in -nostdlib.
We still have to skip a token inside SEARCH_DIR() when -nostdlib is
specified. Previuosly, we didn't skip it, so it caused a parse error.

llvm-svn: 281001
2016-09-08 23:26:54 +00:00
Rui Ueyama c442cff96e Define writeUint and use it. NFC.
llvm-svn: 280994
2016-09-08 21:46:21 +00:00
Davide Italiano e02ba98f8f [ELF] Fix DT_NEEDED value.
Differential Revision: https://reviews.llvm.org/D24363

llvm-svn: 280990
2016-09-08 21:18:38 +00:00
Ed Maste e349b6da2c ELF: clarify error when we don't know the output format
lld differs from GNU ld in that it does not have a built-in default
target emulation. Emulation is always specified via the -m option, or
obtained from the object file(s) being linked. In most cases at least
one ELF object is included in the link, so the emulation is known.

When using lld's (not yet committed) -b binary support with -r, to
convert a binary file into an ELF object we do not have a known
emulation. The error message previously emitted in this case
"-m or at least a .o file required" is accurate but does not offer
much insight. Add text to the error message to give a hint why -m or an
object file is required.

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

llvm-svn: 280989
2016-09-08 21:06:29 +00:00
Rafael Espindola c0028d3d3b Reduce templating. NFC.
llvm-svn: 280986
2016-09-08 20:47:52 +00:00
Rui Ueyama 881406e787 Define '-undefined foo' as an alias to '-undefined=foo'.
llvm-svn: 280985
2016-09-08 20:35:29 +00:00
Ed Maste 2b68ada188 ELF: Report original emulation name in "unknown emulation" error
A trailing _fbsd is stripped from emulation names, but if the result was
still not a valid emulation the error was somewhat confusing.

For example,

% ld.lld -m elf_amd64_fbsd
unknown emulation: elf_amd64

Use the original emulation name in error messages.

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

llvm-svn: 280983
2016-09-08 19:36:22 +00:00
Ed Maste 21e2be6403 ELF: accept -m elf_amd64 as an alias for -m elf_x86_64
In the FreeBSD world x86_64 still has its original name, amd64. Accept
it as an alias.

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

llvm-svn: 280982
2016-09-08 19:30:47 +00:00
Rafael Espindola 868fc9279e Handle globs in global symbol names.
Fixes pr28775.

llvm-svn: 280947
2016-09-08 14:50:55 +00:00
Rafael Espindola 4d1e4d76ee Use a protected destructor instead of a virtual one.
llvm-svn: 280941
2016-09-08 14:11:08 +00:00
Rafael Espindola 042a3f209b Compute section names only once.
This simplifies error handling as there is now only one place in the
code that needs to consider the possibility that the name is
corrupted. Before we would do it in every access.

llvm-svn: 280937
2016-09-08 14:06:08 +00:00
Rafael Espindola 16853bb00f Pack InputSectionData from 72 to 64 bytes. NFC.
llvm-svn: 280925
2016-09-08 12:33:41 +00:00
George Rimar 9fc6143a5b [ELF] - Add virtual destructor to LinkerScriptBase class. NFC.
Absence of it caused a clang warning:
warning: 'lld:🧝:LinkerScriptBase' has virtual functions but non-virtual destructor [-Wnon-virtual-dtor]

At fact we don't need it here because do not destroy this object by
base pointer.

llvm-svn: 280916
2016-09-08 09:59:13 +00:00
Eugene Leviant 36fac7f0d0 Linker script: implement ALIGNOF
Differential revision: https://reviews.llvm.org/D24141

llvm-svn: 280915
2016-09-08 09:08:30 +00:00
Simon Atanasyan 919a58c456 [ELF][MIPS] Fix initialization of TLS-related GOT entries
This patch allows static linking of TLS code. To do that it fixes
GOT entries initialization.

If TLS-related GOT entry created for a preemptible symbol i.e. has
a corresponding dynamic relocation, leave the entry initialized by zero.
Write down adjusted TLS symbol's values otherwise. For the adjustments
calculation use offsets for thread-local storage.

https://www.linux-mips.org/wiki/NPTL

llvm-svn: 280914
2016-09-08 09:07:19 +00:00
Simon Atanasyan af52f6af22 [ELF][MIPS] Update the comment
llvm-svn: 280913
2016-09-08 09:07:12 +00:00
Eugene Leviant 3967ea05a9 Set entry address to 0x0 if no _start symbol
Differential revision: https://reviews.llvm.org/D23925

llvm-svn: 280912
2016-09-08 08:57:51 +00:00
George Rimar 6c55f0e35e [ELF] - Apply clang-format to LinkerScript.cpp, NFC.
llvm-svn: 280911
2016-09-08 08:20:30 +00:00
George Rimar 884e786d38 [ELF] - Linkerscript: simplify access to templated methods from parser.
Previous way of accessing templated methods was a bit bulky,
Patch introduces small interface based solution.

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

llvm-svn: 280910
2016-09-08 08:19:13 +00:00
Rui Ueyama 8239617acd Rename test file. NFC.
llvm-svn: 280904
2016-09-08 03:08:05 +00:00
Ed Maste 4d9947ba09 ELF: Add -Qy as ignored option
GCC passes it by default on powerpc64 on FreeBSD. GNU ld claims "this
option is ignored for SVR4 compatibility", so we can ignore it too.

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

llvm-svn: 280864
2016-09-07 21:10:25 +00:00
Rui Ueyama a3b7546cf7 Fix inconsistent indentation.
llvm-svn: 280860
2016-09-07 20:50:41 +00:00
Rafael Espindola 0a75850fa7 Move field to the base class. NFC.
llvm-svn: 280858
2016-09-07 20:41:19 +00:00
Rafael Espindola 664c6522fa Delete dead field. NFC.
llvm-svn: 280856
2016-09-07 20:37:34 +00:00
Ed Maste 5ad1cbeecb ELF: add version script void function test case
After r280733 we use LLVM's demangler in lld. As a result we no longer
have a discrepancy between f() and f(void) on FreeBSD (due to an issue
with FreeBSD's system demangler).

Restore a test case for a void arg function.

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

llvm-svn: 280831
2016-09-07 17:51:00 +00:00
Rafael Espindola 4a2350e841 Enable test on windows.
It looks like it was disable just because we were missing a demangler.

llvm-svn: 280805
2016-09-07 12:09:10 +00:00
George Rimar bcbbb3987d [ELF] - Sort command line options. NFC.
llvm-svn: 280803
2016-09-07 11:43:18 +00:00
George Rimar a14b13d867 [ELF] - Linkerscript: create multiple output sections for inputs with different attributes.
Previously we combined sections by name if linkerscript was used.
For that we had to disable SHF_MERGE handling temporarily, but then
found that implementing it properly will require additional complexity layers like
subsections or something.
At the same time looks we can live with multiple output sections approach for now.
That patch do this change.

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

llvm-svn: 280801
2016-09-07 10:46:07 +00:00
George Rimar 51da9c7178 [ELF] - Fix for: PR29093 - version script does not support [chars] wildcards
GNU ld supports [chars] wildcards in version scripts, to match a single instance of any of the chars.
Here is an extern example from libstdc++'s version script in FreeBSD:

extern "C++"
{
...

std::locale::_[T-Za-z]*;                                                                                                       
std::[A-Zm]*;                                                            
std::n[^u]*;                                                             
std::nu[^m]*;                                                            
std::num[^e]*;
...

}

Patch adds support for scripts above. This is PR29093.

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

llvm-svn: 280799
2016-09-07 10:19:44 +00:00
George Rimar 8825a5c6ef [ELF] - Enable testcases that uses demangler to run under windows and escape quotes around "C++".
Previously testcases were enabled only for shell.
r280733 added c++ itanium demangler to lld and we can enable them fully.

Also this change make quotes to be escaped:

extern "C++" -> extern \"C++\", which worked before just because we are dropping tokens 
quotes internally at this moment.

llvm-svn: 280797
2016-09-07 09:59:29 +00:00
Eugene Leviant db741e7203 Support ABSOLUE keyword in symbol assignments
This patch allows making section defined symbols absolute:
.foo : {
  begin_foo = ABSOLUTE(.);
  *(.foo)
}

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

llvm-svn: 280788
2016-09-07 07:08:43 +00:00
Rui Ueyama adcdb664cb Simplify a boolean expression by using the De Morgan's law.
llvm-svn: 280766
2016-09-06 22:50:48 +00:00
Rafael Espindola 5b0fb8f4d5 Fix shared library build.
llvm-svn: 280753
2016-09-06 21:06:55 +00:00