Commit Graph

1400 Commits

Author SHA1 Message Date
Jan Vesely ef1e62033b ELF: link with BitWriter module
Fixes build broken by r263055.

llvm-svn: 263064
2016-03-09 21:38:04 +00:00
Rafael Espindola e090fb2891 ELF: Remove non-standard ELF features from AMDGPU target.
Patch by Tom Stellard!

llvm-svn: 263063
2016-03-09 21:37:22 +00:00
Rui Ueyama 2b4df612ec Simplify. NFC.
In this context, MBRef.getBufferIdentifier() == Path.

llvm-svn: 263061
2016-03-09 21:15:17 +00:00
Sean Silva c43ec673b9 Update for Rui's comments on D18006
Somehow I missed them.

llvm-svn: 263057
2016-03-09 20:06:24 +00:00
Sean Silva 35ef3d95eb [lto] Add beginning of -save-temps option.
Summary:
This is useful for debugging issues with LTO.
The option follows the analogous option in ld64 and the gold plugin (per
Rafael's suggestion).

For starters, this only dumps the combined bitcode file.
In a future patch I will add dumping for the .o file.

The naming of the output follows ld64's convention which is slightly more
consistent IMO (consistent `.lto.<extension>` for all the files).

Reviewers: rafael, ruiu

Subscribers: joker.eph, Bigcheese, llvm-commits

Differential Revision: http://reviews.llvm.org/D18006

llvm-svn: 263055
2016-03-09 20:01:08 +00:00
Sean Silva 50d27ff3c1 [lto] Don't lazy load metadata for now.
Summary:
At the very least we hit

    Assertion failed: (((Flags & RF_HaveUnmaterializedMetadata) || Node->isResolved()) && "Unexpected unresolved node"), function MapMetadataImpl, file /Users/Sean/pg/llvm/lib/Transforms/Utils/ValueMapper.cpp, line 375.

on the included test case.

We currently do things like parse the module twice to keep the
implementation minimal. I think it makes sense to add start with eager
loading for similar reasons.

Reviewers: rafael

Subscribers: ruiu, Bigcheese, llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D17982

llvm-svn: 263045
2016-03-09 18:38:40 +00:00
George Rimar 599d77246d Fixed "not all control paths return a value" warning. NFC.
llvm-svn: 263040
2016-03-09 18:05:34 +00:00
George Rimar 3c45ed2f5e [ELF] - Issue an error if trying to link object that uses splitstacks.
Each object file compiled in split stack mode will have an empty
section with a special name: .note.GNU-split-stack

We don't support this in linker now, so patch just adds an error out for that.

Differential revision: http://reviews.llvm.org/D17918

llvm-svn: 263039
2016-03-09 18:01:45 +00:00
Rafael Espindola 972b236c30 Simplify: SHN_ABS is >= SHN_LORESERVE.
llvm-svn: 263012
2016-03-09 14:31:18 +00:00
Sean Silva 7255d0b068 [lto] Avoid duplicate symbol error for appending linkage.
Summary:
Is there any other code needed for correctly handling appending linkage?
Do we need to do something more with @llvm.global_ctors in
SymbolTable.cpp:addBitcodeFile; otherwise the combined bitcode module
won't have all the global ctors.

Reviewers: rafael

Subscribers: Bigcheese, llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D17975

llvm-svn: 262992
2016-03-09 03:42:39 +00:00
Sean Silva 3dbf9a31b5 Avoid unnecessary qualification.
Thanks to Rui for spotting this.

llvm-svn: 262983
2016-03-09 02:02:26 +00:00
Sean Silva 31a5ab9e3b [lto] Record whether a variable is TLS.
Summary:

Reviewers: rafael

Subscribers: Bigcheese, llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D17974

llvm-svn: 262975
2016-03-09 00:47:47 +00:00
Rafael Espindola 708453d99f Assume GV is not null for now.
It will come back when we add support for inline asm in .bc files.

llvm-svn: 262972
2016-03-09 00:31:06 +00:00
Sean Silva b284e71e03 [lto] Don't add variables with private linkage to the symbol table.
Summary:
This causes the issue in PR26872 to go away now that we aren't creating
symbols for the string literals, but that may just be concealing a
deeper problem, so best to keep that PR open.

Reviewers: rafael

Subscribers: Bigcheese, llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D17971

llvm-svn: 262968
2016-03-08 23:50:56 +00:00
Rafael Espindola e02f4dfb9e Remove an unnecessary hack.
It doesn't look like anything is depending on using local dynamic tls
relocations with preemptable  symbols.

llvm-svn: 262957
2016-03-08 21:17:31 +00:00
Rafael Espindola 1f04c44885 Delete isTlsDynRel.
It was a badly specified hack for when a tls relocation should be
propagated to the dynamic relocation table.

This replaces it with a not as bad hack of saying that a local dynamic
tls relocation is never preempted.

I will try to remove even that second hack in the next patch.

llvm-svn: 262955
2016-03-08 20:24:36 +00:00
Rafael Espindola 0650192094 Revert "ELF: Add /lib and /usr/lib as default search paths."
It was causing errors like

/lib/libc.so.6 is incompatible with elf_x86_64

when linking on Fedora.

Every system has different default paths. It seems better to just trust
the driver to pass the correct -L options.

This reverts commit 262910.

llvm-svn: 262941
2016-03-08 17:13:12 +00:00
Rui Ueyama 3f9f09265b ELF: Rename NoInhibitExec -> NoinhibitExec.
The variables corresponding to command line options are named mechanically.
Because the option for the variable is -noinhibit-exec and not -no-inhibit-exec,
it should be name this way.

llvm-svn: 262911
2016-03-08 04:06:29 +00:00
Rui Ueyama b9883d55d8 ELF: Add /lib and /usr/lib as default search paths.
GNU ld and gold have these paths as default search paths.
If you don't want these directories, pass -nostdlib.

llvm-svn: 262910
2016-03-08 04:06:27 +00:00
Rafael Espindola 37bcaac179 Add support for common symbols.
llvm-svn: 262848
2016-03-07 19:15:57 +00:00
Rui Ueyama 68fae23475 Do not use "default" for a fully-covered switch.
llvm-svn: 262846
2016-03-07 19:06:14 +00:00
Rafael Espindola e711fc3767 Adjust the .bss alignment to include common symbols.
llvm-svn: 262840
2016-03-07 17:43:39 +00:00
Rafael Espindola 4f29c1a337 lto: Record visibility in defined symbols.
llvm-svn: 262835
2016-03-07 17:14:36 +00:00
Rui Ueyama fd4fee599e Split BitcodeFile::parse. NFC.
llvm-svn: 262813
2016-03-07 00:54:17 +00:00
George Rimar 2f0fab53e4 [ELF] - Simplify a SymbolBody class interface a bit.
Get rid of few accessors in that class, and replace
them with direct fields access.

Differential revision: http://reviews.llvm.org/D17879

llvm-svn: 262796
2016-03-06 06:26:18 +00:00
George Rimar 4d1d16d0ed Fixed formatting issues in AArch64 target methods. NFC.
llvm-svn: 262795
2016-03-06 06:16:05 +00:00
George Rimar 7b8850f2bd [ELF] - Changed return type of Target::relaxTls()
Patch changes the return type of Target::relaxTls 
to size_t from unsigned. That is consistent with
its use from other code.

Change was reviewed http://reviews.llvm.org/D17882
and asked to commit separately from that patch above.

llvm-svn: 262794
2016-03-06 06:09:50 +00:00
George Rimar 98b060d228 [ELF] - Use the uint32_t instead of unsigned in Target class for relocations types
Patch changes all relocations types to be uint32_t and also 
fixes some dependent inconsistency in callers code.

Differential revision: http://reviews.llvm.org/D17882

llvm-svn: 262793
2016-03-06 06:01:07 +00:00
Rafael Espindola 7f6d50b229 Use IRMover directly.
This has a few advantages:
* If lld selected a non bitcode symbol, be the bitcode GV is not merged
* lib/Linker is not redoing symbol resolution.

llvm-svn: 262773
2016-03-05 14:51:51 +00:00
Rafael Espindola 888f2c33d4 lto: Start taking symbol visibility into consideration.
llvm-svn: 262761
2016-03-05 00:09:37 +00:00
Rafael Espindola d405f4721c Refactor target independent code.
The rules for when we can relax tls relocations are target independent.
The only things that are target dependent are the relocation values.

llvm-svn: 262748
2016-03-04 21:37:09 +00:00
Rui Ueyama d4530c6eb8 Add a comment about _DYNAMIC.
llvm-svn: 262735
2016-03-04 18:34:14 +00:00
Rafael Espindola 1ea51d2718 Refactor duplicated code.
llvm-svn: 262720
2016-03-04 16:14:19 +00:00
Simon Atanasyan 4e18a3163d [ELF][MIPS] Factor out the code reading and sign-extending low 16-bits of 32-bit word. NFC
llvm-svn: 262708
2016-03-04 10:55:29 +00:00
Simon Atanasyan 0dcf541692 [ELF][MIPS] Factor out the code writing relocation result into low 16-bit of destination. NFC
llvm-svn: 262707
2016-03-04 10:55:24 +00:00
Simon Atanasyan 3b37785fee [ELF][MIPS] Factor out the code reading and calculating AHL addend into the separate function. NFC
llvm-svn: 262706
2016-03-04 10:55:20 +00:00
Simon Atanasyan deed55d706 [ELF][MIPS] Use writeMipsHi16 to apply result of R_MIPS_PCHI16 relocation. NFC
llvm-svn: 262705
2016-03-04 10:55:16 +00:00
Simon Atanasyan a888e6726f [ELF][MIPS] Replace S and A arguments of the writeMipsHi16 function by the single argument V. NFC
llvm-svn: 262704
2016-03-04 10:55:12 +00:00
Simon Atanasyan 3474b907dd [ELF][MIPS] s/applyMipsHi16Reloc/writeMipsHi16/ NFC
llvm-svn: 262703
2016-03-04 10:55:04 +00:00
Rui Ueyama a3cb80adfc Use check function.
llvm-svn: 262685
2016-03-04 01:56:52 +00:00
Davide Italiano 255730cdc5 [ELF] Generalize symbol type handling.
SymbolBody constructor and friends take isFunc and isTLS boolean arguments.
ELF symbols have already a type so than be easily passed as argument.
If we want to support another type, this scheme is not good enough, that is,
the current code logic would require passing another `bool isObject` around.
Up to two argument, this stretching exercise was a little bit goofy but
still acceptable, but with more types to support, is just too much, IMHO.

Change the code so that the type is passed instead.

Differential Revision:   http://reviews.llvm.org/D17871

llvm-svn: 262684
2016-03-04 01:55:28 +00:00
Rafael Espindola 75714f618c Rename 'fatal' to 'check' when it doesn't always fail.
llvm-svn: 262666
2016-03-03 22:24:39 +00:00
Rui Ueyama 6df27e7f21 Remove dead code.
llvm-svn: 262662
2016-03-03 21:56:21 +00:00
Davide Italiano 05920b14c8 [ELF] Be slightly more consistent, use uint8_t instead of unsigned char.
llvm-svn: 262660
2016-03-03 21:54:03 +00:00
Rafael Espindola ec9957bd0b Delete dead code.
llvm-svn: 262653
2016-03-03 20:45:26 +00:00
George Rimar e5960ceb6b [ELF] - Do not allow .bss to occupy the file space when producing relocatable output
When generating relocatable output SHT_NOBITS sections
were still occupy the file space.

Differential revision: http://reviews.llvm.org/D17857

llvm-svn: 262650
2016-03-03 20:24:14 +00:00
Rafael Espindola 005d84430d Fix PR26818.
The hack of using a plt address as the address of an undefined function
only works in executables. Don't try it with shared libraries.

llvm-svn: 262642
2016-03-03 18:44:38 +00:00
Rafael Espindola 1130935c4a Simplify error handling.
This makes fatal return T when there is no error. This avoids the need
for quite a few temporaries.

llvm-svn: 262626
2016-03-03 16:21:44 +00:00
George Rimar 4cfe572932 [ELF] - add support for relocations against local symbols when producing relocatable output.
There was a known limitation for -r option:
relocations against local symbols were not supported. 
For example rel[a].eh_frame sections contained relocations against sections
and that was not supported for -r before. Patch fixes that.

Differential review: http://reviews.llvm.org/D17813

llvm-svn: 262590
2016-03-03 07:49:35 +00:00
Rui Ueyama eb3413e43a Replace ECRAII class with a function.
RCRAII class was a bit tricky. This patch removes that.

llvm-svn: 262586
2016-03-03 06:22:29 +00:00
Rui Ueyama a1ee70ba75 Allow joined options to fix http://llvm.org/pr26730.
llvm-svn: 262550
2016-03-03 00:09:02 +00:00
Rui Ueyama a453c0a5ad Merge DarwinLdDriver and Driver.
Now that DarwinLdDriver is the only derived class of Driver.
This patch merges them and actually removed the class because
they can now just be non-member functions. This change simplifies
a common header, Driver.h.

http://reviews.llvm.org/D17788

llvm-svn: 262502
2016-03-02 19:08:05 +00:00
Rafael Espindola cdf3a2a5be 1Fix handling of undef in partial LTO.
llvm-svn: 262497
2016-03-02 18:21:46 +00:00
Rafael Espindola 3ca9ee0c53 LTO: Use the correct relocation model.
llvm-svn: 262492
2016-03-02 17:21:06 +00:00
Rafael Espindola 4de44b7ef8 Handle comdat in LTO.
llvm-svn: 262489
2016-03-02 15:43:50 +00:00
Simon Atanasyan ea423e261f [ELF] Fix reading of PC values of FDEs
The patch fixes two related problems:
- If CIE augmentation string has 'L' token the CIE contains a byte
  defines LSDA encoding. We should skip this byte in `getFdeEncoding`
  routine. Before this fix we do not skip it and if the next token
  is 'R' treat this byte as FDE encoding.
- FDE encoding format has separate flags e.g. DW_EH_PE_pcrel for
  definition of relative pointers. We should add .eh_frame address to
  the PC value iif the DW_EH_PE_pcrel is specified.

http://www.airs.com/blog/archives/460

There is one more not fixed problem in this code. If PC value is encoded
using signed relative format e.g. DW_EH_PE_sdata4 | DW_EH_PE_pcrel we
should sign extend result of read32 to perform calculation correctly.
I am going to fix that in a separate patch.

Differential Revision: http://reviews.llvm.org/D17733

llvm-svn: 262461
2016-03-02 05:38:42 +00:00
Rui Ueyama 148945eb17 Fix --help message.
llvm-svn: 262413
2016-03-01 22:17:09 +00:00
George Rimar 262b927d36 [ELF] - handle of command line options incompatible with -r
Patch handles the command line options
incompatible with relocatable output.

Differential revision: http://reviews.llvm.org/D17758

llvm-svn: 262377
2016-03-01 19:38:51 +00:00
George Rimar 2abc587c1e [ELF] - More direct implementation of edata/etext
As was suggested in mails, this patch implements edata/etext
symbols in a more direct way.
It iterates through PT_LOADs.

Result seems to be the same and equal to gold output.

Differential revision: http://reviews.llvm.org/D17755

llvm-svn: 262369
2016-03-01 19:18:07 +00:00
George Rimar c1034a85d0 [ELF] - do not create special symbols when creating relocatable output
__start_/__end_ <section-name> symbols and other specials like:
preinit_array_start/end
init_array_start/end
fini_array_start/end

should not be created by linker when creating relocatable files.

Differential revision: http://reviews.llvm.org/D17774

llvm-svn: 262366
2016-03-01 19:12:35 +00:00
George Rimar aa4dc20f09 [ELF] - Create _DYNAMIC symbol for dynamic output
lld needs to provide _DYNAMIC symbol when creating a shared library
both bfd and gold do that.

This should fix the https://llvm.org/bugs/show_bug.cgi?id=26732

Differential revision: http://reviews.llvm.org/D17607

llvm-svn: 262348
2016-03-01 16:23:13 +00:00
Rafael Espindola 393877d51b Fix BUILD_SHARED_LIBS build.
llvm-svn: 262345
2016-03-01 15:56:53 +00:00
Rafael Espindola 9907eb0b0a Produce PT_NOTE program headers.
llvm-svn: 262331
2016-03-01 13:23:29 +00:00
George Rimar 6de3f63bb0 [ELF] use of already declared reference instead of indirect access to fields. NFC.
llvm-svn: 262315
2016-03-01 08:46:03 +00:00
Rafael Espindola 1b625535f0 lto: don't fetch members for weak undef.
llvm-svn: 262225
2016-02-29 14:29:48 +00:00
Rafael Espindola 9bcbfd7d42 Remove bogus assert.
llvm-svn: 262219
2016-02-29 13:46:39 +00:00
Rui Ueyama e7b330052f Move functionality of UniversalDriver to the entry point file.
UniversalDriver was used as a dispatcher to each platform-specific driver.
It had its own Options.td file. It was not just too much to parse only a
few options (we only want to parse -core, -flavor or argv[0]),
but also interpreted arguments too early. For example, if you invoke lld as
"lld -flavor gnu ... -help", then you'd get the UniversalDriver's help
message instead of GnuDriver's. This patch eliminates the use of Options
from the dispatcher.

http://reviews.llvm.org/D17686

llvm-svn: 262190
2016-02-28 19:50:14 +00:00
Rui Ueyama 3e80897627 ELF: Remove OutSection class and use a map instead.
It is easier to handle section filler data separately rather than
merging with section names.

llvm-svn: 262175
2016-02-28 05:09:11 +00:00
Rui Ueyama 7a6c9aed7a Simplify. NFC.
llvm-svn: 262174
2016-02-28 04:48:54 +00:00
Rui Ueyama 7c82dbf333 Remove unused #include.
llvm-svn: 262169
2016-02-28 03:27:09 +00:00
Rui Ueyama 1eb9f44118 ELF: Add --help option.
llvm-svn: 262168
2016-02-28 03:18:09 +00:00
Rui Ueyama 1abcf370fd ELF: Add --version option.
llvm-svn: 262167
2016-02-28 03:18:07 +00:00
Rafael Espindola e0df00b91f Rename elf2 to elf.
llvm-svn: 262159
2016-02-28 00:25:54 +00:00
Rui Ueyama 40c589048e ELF: Remove relSize function from ICF.cpp. NFC.
llvm-svn: 262155
2016-02-27 20:29:45 +00:00
Rafael Espindola 18f0950783 Report duplicated symbols in bitcode.
llvm-svn: 262076
2016-02-26 21:49:38 +00:00
Rafael Espindola 297ce4ece9 Make SymbolBodies private.
This makes BitcodeFile a bit closer to ObjectFile.

If anyone prefers I can go the other way and delete getSymbols from
ObjectFile.

llvm-svn: 262072
2016-02-26 21:31:34 +00:00
Rui Ueyama 68e15559b8 Fix broken buildbots.
llvm-svn: 262034
2016-02-26 16:49:54 +00:00
Rui Ueyama 4d169bdca2 Simplify. NFC.
Regarding the comment, it is out of context because it describes
what it does not do there. It got too long because it was originally
two different comments that were simply merged together.
The semantics is described in fixAbsoluteSymbols, so we don't need it.

llvm-svn: 262031
2016-02-26 16:38:39 +00:00
Rui Ueyama dad77c593b Simplify. NFC.
llvm-svn: 262027
2016-02-26 15:42:06 +00:00
Rui Ueyama 72acaa1d17 Add comment on AMDGPU that the difference has no obvious reason.
llvm-svn: 262026
2016-02-26 15:39:26 +00:00
Rui Ueyama eec23eb319 Fix unsafe dereference.
Bound may point to one element beyond the end of the
vector, so *Bound is not safe.

llvm-svn: 262022
2016-02-26 15:13:24 +00:00
George Rimar e2ee72b509 [ELF] - Implemented linkerscript sections padding.
BSD linker scripts contain special cases to add NOP
padding to code sections. Syntax is next:

.init:
 {
   KEEP (*(.init))
 } =0x90909090
(0x90 is NOP)

This patch implements that functionality.

llvm-svn: 262020
2016-02-26 14:48:31 +00:00
George Rimar 9e8593949d Description of symbols is avalable here:
https://docs.oracle.com/cd/E53394_01/html/E54766/u-etext-3c.html

It is said that:
_etext - The address of _etext is the first 
location after the last read-only loadable segment.

_edata - The address of _edata is the first 
location after the last read-write loadable segment.

_end - If the address of _edata is greater than the address 
of _etext, the address of _end is same as the address of _edata.

In real life _end and _edata has different values for that case.
Both gold/bfd set _edata to the end of the last non SHT_NOBITS section.
This patch do the same for consistency.

It should fix the https://llvm.org/bugs/show_bug.cgi?id=26729.

Differential revision: http://reviews.llvm.org/D17601

llvm-svn: 262019
2016-02-26 14:36:36 +00:00
Rafael Espindola a350e266aa Refactor multiple calls to canBePreempted.
llvm-svn: 262018
2016-02-26 14:33:23 +00:00
Rafael Espindola 993f0273e3 Fix some confusion about what can be preempted.
For shared libraries we allow any weak undefined symbol to eventually be
resolved, even if we never see a definition in another .so. This matches
the behavior when handling other undefined symbols in a shared library.

For executables, we require seeing a definition in a .so or resolve it
to zero. This is also similar to how non weak symbols are handled.

llvm-svn: 262017
2016-02-26 14:27:47 +00:00
Rui Ueyama dc9cc6a574 Remove redundant template instantiations.
This class is used only in this translation unit, so no need
to instantiate them explicitly.

llvm-svn: 261951
2016-02-26 01:30:35 +00:00
Rui Ueyama bca6eb85a3 Fix typo in comment.
llvm-svn: 261943
2016-02-26 00:10:01 +00:00
Rui Ueyama ad59b65f18 ELF: Add '*' to auto.
llvm-svn: 261941
2016-02-25 23:58:21 +00:00
Rui Ueyama a354c5c433 ELF: Create MIPS .rld_map section earlier.
This is the usual way of instantiating a globally-visible section.

llvm-svn: 261938
2016-02-25 23:54:49 +00:00
Rafael Espindola 58e4c6bdba Delete dead code.
When this code was first added it was compensating for the code deciding
to create plt entries for directly referenced functions being too aggressive.

That has since been fixed, so we don't need this anymore.

llvm-svn: 261933
2016-02-25 23:16:33 +00:00
Rafael Espindola dd7f4e33ea Move common code out of target specific hooks.
llvm-svn: 261932
2016-02-25 23:03:55 +00:00
Simon Atanasyan 860fbf094e [ELF][MIPS] Calculate combined addend for R_MIPS_GOT16 against local symbol
R_MIPS_GOT16 relocation against local symbol requires index of a local
GOT entry which contains page address corresponds to sum of the symbol
address and addend. The addend in that case is calculated using addends
from the R_MIPS_GOT16 and paired R_MIPS_LO16 relocations.

Differential Revision: http://reviews.llvm.org/D17610

llvm-svn: 261930
2016-02-25 21:33:56 +00:00
Simon Atanasyan bea9698b0e [ELF][MIPS] Remove redundant namespace qualifier. NFC
llvm-svn: 261928
2016-02-25 21:09:05 +00:00
Rui Ueyama 3095148015 ELF: Split Writer::addPredefiendSections. NFC.
llvm-svn: 261924
2016-02-25 19:34:37 +00:00
Rui Ueyama 4cea4e81d4 ELF: Split Writer::writeHeader. NFC.
llvm-svn: 261923
2016-02-25 19:28:37 +00:00
Rui Ueyama 10bd283041 ELF: Define log() to print out message if --verbose is given.
llvm-svn: 261919
2016-02-25 18:56:01 +00:00
Rui Ueyama 6a9ef8550c Remove default values which are always overwritten.
llvm-svn: 261913
2016-02-25 18:49:09 +00:00
Rui Ueyama 0b28952993 ELF: Implement ICF.
This patch implements the same algorithm as LLD/COFF's ICF. I'm
not going to repeat the same description about how it works, so you
want to read the comment in ICF.cpp in this patch if you want to know
the details. This algorithm should be more powerful than the ICF
algorithm implemented in GNU gold. It can even merge mutually-recursive
functions (which is harder than one might think).

ICF is a fairly effective size optimization. Here are some examples.

 LLD:   37.14 MB -> 35.80 MB (-3.6%)
 Clang: 59.41 MB -> 57.80 MB (-2.7%)

The lacking feature is "safe" version of ICF. This merges all
identical sections. That is not compatible with a C/C++ language
requirement that two distinct functions must have distinct addresses.

But as long as your program do not rely on the pointer equality
(which is in many cases true), your program should work with the
feature. LLD works fine for example.

GNU gold implements so-called "safe ICF" that identifies functions
that are safe to merge by heuristics -- for example, gold thinks
that constructors are safe to merge because there is no way to
take an address of a constructor in C++. We have a different idea
which David Majnemer suggested that we add NOPs at beginning of
merged functions so that two or more pointers can have distinct
values. We can do whichever we want, but this patch does not
include neither.

http://reviews.llvm.org/D17529

llvm-svn: 261912
2016-02-25 18:43:51 +00:00
Rafael Espindola 148445ef98 Add support for weak symbols in LTO.
llvm-svn: 261881
2016-02-25 16:25:41 +00:00
Rafael Espindola f1ce4cf1f1 Remove unnecessary prefix.
llvm-svn: 261880
2016-02-25 16:20:00 +00:00
Simon Atanasyan d040a58da3 [ELF][MIPS] Add STO_MIPS_PLT flag to the symbols require pointer equality
On MIPS we need to mark symbol which has a PLT entry and requires
pointer equality by STO_MIPS_PLT flag. That is necessary to help
dynamic linker distinguish such symbols and MIPS lazy-binding stubs.

https://sourceware.org/ml/binutils/2008-07/txt00000.txt

Differential Revision: http://reviews.llvm.org/D17593

llvm-svn: 261879
2016-02-25 16:19:15 +00:00
George Rimar 12737b7f72 [ELF] - Referencing __start or __stop should keep the section from GC.
This fixes the https://llvm.org/bugs/show_bug.cgi?id=22906 bug.

In GNU Binutils, a reference to start or stop is sufficient to 
prevent the section from being garbage collected.
Patch implements the same behavior for lld.

Differential revision: http://reviews.llvm.org/D17502

llvm-svn: 261840
2016-02-25 08:40:26 +00:00
George Rimar 58941ee12a [ELF2] - Basic implementation of -r/--relocatable
-r, -relocatable - Generate relocatable output

Currently does not have support for files containing 
relocation sections with entries that refer to local 
symbols (like rel[a].eh_frame which refer to sections
and not to symbols)

Differential revision: http://reviews.llvm.org/D14382

llvm-svn: 261838
2016-02-25 08:23:37 +00:00
Simon Atanasyan 49bc69b9bb [ELF][MIPS] Enumerate absolute MIPS relocations in the isRelRelative
This commit does two related thing. At first, it enumerates supported
absolute MIPS relocations in the `MipsTargetInfo<ELFT>::isRelRelative`
method. In that case the code is shorter and the case switch does not
tend to grow. At second, it prevents R_MIPS_COPY and PLT creation for
relative relocations. For almost all relative MIPS relocations like
R_MIPS_PC19_S2, R_MIPS_PCHI16 etc it does not have a sence. The only
exception is R_MIPS_PC32. GNU linker creates a copy relocation or PLT
entry for it. But I could not find any real test case uses R_MIPS_PC32
with DSO defined symbol as a target. So for now I prefer to skip this
case to simplify the LLD code.

llvm-svn: 261822
2016-02-25 05:03:52 +00:00
Rafael Espindola a598a3a08a Mark R_AARCH64_CALL26 as relative.
llvm-svn: 261783
2016-02-24 22:07:12 +00:00
Rafael Espindola 47ed542328 Mark R_AARCH64_ADD_ABS_LO12_NC as relative.
llvm-svn: 261772
2016-02-24 21:48:06 +00:00
Rafael Espindola 57ca270b7a Mark R_AARCH64_LDST64_ABS_LO12_NC as relative.
llvm-svn: 261769
2016-02-24 20:52:58 +00:00
Rafael Espindola 40afcb547e Mark R_AARCH64_LDST32_ABS_LO12_NC as relative.
llvm-svn: 261766
2016-02-24 20:18:06 +00:00
Rafael Espindola 9a3bb54b2e R_AARCH64_LDST8_ABS_LO12_NC is effectivelly relative.
It only sets the low bits and given the page alignment of PT_LOAD the
dynamic linker can only change the high ones.

llvm-svn: 261765
2016-02-24 19:58:50 +00:00
Rafael Espindola c36e97ae39 R_AARCH64_ADR_PREL_PG_HI21 is relative.
llvm-svn: 261764
2016-02-24 19:36:30 +00:00
Rui Ueyama 733153de3c ELF: Do not instantiate InputSectionBase::Discarded.
"Discarded" section is a marker for discarded sections, and we do not
use the instance except for checking its identity. In that sense, it
is just another type of a "null" pointer for InputSectionBase. So,
it doesn't have to be a real instance of InputSectionBase class.

In this patch, we no longer instantiate Discarded section but instead
use -1 as a pointer value. This eliminates a global variable which
needed initialization at startup.

llvm-svn: 261761
2016-02-24 18:33:35 +00:00
Rafael Espindola 795dc5a0fb Move target independent code out of x86_64 only path.
The logic for deciding if an undefined symbol should have the value of a
got entry is not target specific.

llvm-svn: 261760
2016-02-24 18:24:23 +00:00
Rafael Espindola b508f520e7 Create implicit plt entries for R_X86_64_32S.
llvm-svn: 261749
2016-02-24 16:37:47 +00:00
Rafael Espindola a4e35f7092 Mark R_AARCH64_PREL32 as relative.
llvm-svn: 261747
2016-02-24 16:15:13 +00:00
George Rimar c3794e5834 [ELF] - replaced std::function with raw pointers in LinkerScript.cpp
Change as was proposed by David Blaikie.

Differential revision: http://reviews.llvm.org/D17499

llvm-svn: 261729
2016-02-24 09:21:47 +00:00
George Rimar cb2aeb66e4 [ELF] - Teach input section wildcard patterns to recognize '?' meta character.
`?' - matches any single character
https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html

This is used in linker scripts.

Differential revision: http://reviews.llvm.org/D17290

llvm-svn: 261726
2016-02-24 08:49:50 +00:00
Rui Ueyama 5ac589171d ELF: Remove InputSectionBase::getAlign and instead add Align member.
This is a preparation for ICF. If we merge two sections, we want to
align the merged section at the largest alignment requirement.
That means we want to update the alignment value, which was
impossible before this patch because Header is a const value.

llvm-svn: 261712
2016-02-24 00:38:18 +00:00
Rui Ueyama 8fc070d64d ELF: Remove InputSectionBase::isLive and use Live member instead. NFC.
This is also a preparation for ICF.

llvm-svn: 261711
2016-02-24 00:23:15 +00:00
Rui Ueyama d7e4a281c4 ELF: Make some functions constant. NFC.
This is a preparation for ICF.

llvm-svn: 261710
2016-02-24 00:23:13 +00:00
Rafael Espindola 435c00f39c Fix the aarch64 logic for dynamic relocations.
There is nothing aarch64 specific in here. If a symbol can be preempted,
we need to copy the full relocation to the dynamic linker.

If a symbol cannot be preempted, we can make the dynamic linker life
easier and produce a relative relocation.

This is directly equivalent to R_X86_64_64 to R_x86_64_RELATIVE
conversion.

llvm-svn: 261678
2016-02-23 20:19:44 +00:00
Rafael Espindola f7ae359d2c Simplify. NFC.
llvm-svn: 261668
2016-02-23 18:53:29 +00:00
Rafael Espindola 75baf09be5 Don't include tbss's alignment in offset.
The .tbss section is in the middle of a PT_LOAD. Whatever treatment we
give to its address we must also give to the offset.

We were ignoring it for address computations, but not for offset.

Fixes pr26712.

llvm-svn: 261667
2016-02-23 18:39:55 +00:00
Rui Ueyama c89bff2ce1 Handle bitcode files in archive files with --whole-archive.
This patch moves BitcodeFile instantiation into createObjectFile.
Previously, we handle bitcode files outside that function and did
not handle for --whole-archive.

http://reviews.llvm.org/D17527

llvm-svn: 261663
2016-02-23 18:17:11 +00:00
Adhemerval Zanella 668ad0ffcb [lld] [ELF/AArch64] Fix R_AARCH64_ABS64 in Shared mode
This patch fixes the R_AARCH64_ABS64 relocation when used in shared mode,
where it requires a dynamic R_AARCH64_RELATIVE relocation. To correct set
the addend on the dynamic relocation (since it will be used by the dynamic
linker), a new TargetInfo specific hook was created (getDynRelativeAddend)
to get the correct addend based on relocation type.

The patch fixes the issues when creating shared library code against
{init,fini}_array, where it issues R_AARCH64_ABS64 relocation against
local symbols.

llvm-svn: 261651
2016-02-23 16:54:40 +00:00
George Rimar 481c2ce64b [ELF] - Linkerscript KEEP command.
When link-time garbage collection is in use (-gc-sections), it is 
often useful to mark sections that should not be eliminated. 
This is accomplished by surrounding an input section's wildcard 
entry with KEEP(). Patch implements that command.

Differential revision: http://reviews.llvm.org/D17242

llvm-svn: 261616
2016-02-23 07:47:54 +00:00
Rui Ueyama c00718fd8e Use TinyPtrVector<Ty *> instead of SmallVector<Ty *, 1>.
Thanks to Sean Silva for the suggestion.

llvm-svn: 261606
2016-02-23 03:34:37 +00:00
Rafael Espindola 8176d57d62 Handle a weak undefined tls to archive member.
A weak undefined should not fetch archive members, so we have to keep
the Lazy symbol.

That means the lazy symbol has to encode information about the original
weak undef.

Fixes pr25762.

llvm-svn: 261591
2016-02-22 23:19:29 +00:00
Rafael Espindola 5e8b54afdb Remove a trivial getter.
llvm-svn: 261590
2016-02-22 23:16:05 +00:00
Rafael Espindola fb1533b326 Don't create copy relocs in shared libraries.
This fixes PR26699.

llvm-svn: 261576
2016-02-22 21:23:29 +00:00
Rafael Espindola 56da313e86 Correctly handle two gd relocations to the same symbol.
Fixes PR26676.

llvm-svn: 261561
2016-02-22 19:57:55 +00:00
Rafael Espindola 6feecec0b0 Handle undef symbols in LTO.
This also handles bc files is archives.

llvm-svn: 261374
2016-02-19 22:50:16 +00:00
Rafael Espindola 7efa5be205 Add support for merging strings with alignment larger than one char.
This reduces the .rodata of scyladb from 4501932 to 4334639 bytes (1.038
times smaller).

I don't think it is critical to support tail merging, just exact
duplicates, but given the code organization it was actually a bit easier
to support both.

llvm-svn: 261327
2016-02-19 14:17:40 +00:00
George Rimar d2389bfd9d Attemp to heal windows buildbot
http://lab.llvm.org:8011/builders/sanitizer-windows/builds/17414

llvm-svn: 261322
2016-02-19 11:56:49 +00:00
George Rimar f23b23200d [ELF] - Minor refactor of LinkerScript file
* Else-ifs in ScriptParser::run() replaced with std::function + map
* Reordered members of ScriptParser

Differential revision: http://reviews.llvm.org/D17256

llvm-svn: 261317
2016-02-19 10:45:45 +00:00
George Rimar e9e1d323c6 Fixed comments formatting. NFC.
llvm-svn: 261214
2016-02-18 15:17:01 +00:00
George Rimar 9bec24ab88 Renamed sh_type -> Type, sh_flags -> Flags in arguments. NFC.
llvm-svn: 261213
2016-02-18 14:20:08 +00:00
Rui Ueyama a2b1f45ded Make getOffset a member function of DynamicReloc<ELFT>.
Logically it belongs to DynamicReloc, and it is more readable to
be a member of the class.

llvm-svn: 261069
2016-02-17 06:08:42 +00:00
Rui Ueyama 861c731ccc Use shorter names for the .gnu.hash class.
llvm-svn: 261067
2016-02-17 05:40:03 +00:00
Rui Ueyama 91c0a5db01 Use stable_partition instead of erasing all elements and fill it again.
llvm-svn: 261066
2016-02-17 05:40:01 +00:00
Rui Ueyama c2e863a0d8 Use an accurate type instead of unsigned.
These values are offsets in the string table (which must fit in
host computer's memory space), so size_t is better than unsigned.

llvm-svn: 261065
2016-02-17 05:06:40 +00:00
Rui Ueyama 874e7aee29 Split SymbolTableSection::writeGlobalSymbols.
Previously, we added garbage-collected symbols to the symbol table
and filter them out when we were writing symbols to the file. In
this patch, garbage-collected symbols are filtered out from beginning.

llvm-svn: 261064
2016-02-17 04:56:44 +00:00
Rafael Espindola f8b8b7b5d0 Don't create multiple .got.plt entries for the same symbol.
We were doing it for ifunc symbols.

llvm-svn: 260980
2016-02-16 16:46:31 +00:00
Rafael Espindola 8ae1290058 Merge multiple tdata.* into a single section.
llvm-svn: 260977
2016-02-16 16:12:06 +00:00
Rafael Espindola 1492820aaa Merge multiple .gcc_except_table.* into a single section.
llvm-svn: 260976
2016-02-16 16:05:27 +00:00
Rafael Espindola b032aa1b2b Merge multiple .tbss.* sections into one output section.
llvm-svn: 260974
2016-02-16 15:57:07 +00:00
Saleem Abdulrasool c0571e1261 ELF: silence -Wcast-qual warnings from GCC
Silence 4 -Wcast-qual warnings from GCC 5.1.  NFC.

llvm-svn: 260871
2016-02-15 03:45:18 +00:00
Rui Ueyama 1ebc8ed78a ELF: Add wildcard pattern matching to SECTIONS linker script command.
Each rule in SECTIONS commands is something like ".foo *(.baz.*)",
which instructs the linker to collect all sections whose name matches
".baz.*" from all files and put them into .foo section.

Previously, we didn't recognize the wildcard character. This patch
adds that feature.

Performance impact is a bit concerning because a linker script can
contain hundreds of SECTIONS rules, and doing pattern matching against
each rule would be too expensive. We could merge all patterns into
single DFA so that it takes O(n) to the input size. However, it is
probably too much at this moment -- we don't know whether the
performance of pattern matching matters or not. So I chose to
implement the simplest algorithm in this patch. I hope this simple
pattern matcher is sufficient.

llvm-svn: 260745
2016-02-12 21:47:28 +00:00
Rafael Espindola ac458405bf Trying to fix the MSVC build.
llvm-svn: 260743
2016-02-12 21:36:59 +00:00
Rafael Espindola f1d598c2f6 Try to fix the build in some bots.
llvm-svn: 260736
2016-02-12 21:17:10 +00:00
Rafael Espindola 9f77ef0c08 Add initial LTO support.
llvm-svn: 260726
2016-02-12 20:54:57 +00:00
Rui Ueyama e9c5806593 ELF: Remove use of MapVector from LinkerScript.
We don't have to use a MapVector here. Instead, just std::vector suffices.

llvm-svn: 260724
2016-02-12 20:41:43 +00:00
Rafael Espindola 852860e920 make needsPlt a pure predicate.
llvm-svn: 260685
2016-02-12 15:47:37 +00:00
Adhemerval Zanella 74bcf03f87 [lld] [ELF/AArch64] Add support to some GD/LE/IS TLS relocations
This patch adds some TLS relocations and relaxations for AArch64.
Some Global-Dynamic relocation are handled by optimizing them to
Local-Exec (Initial-Exec is not yet supported). They are:

 - R_AARCH64_TLSDESC_ADR_PAGE21
 - R_AARCH64_TLSDESC_LD64_LO12_NC
 - R_AARCH64_TLSDESC_ADD_LO12_NC
 - R_AARCH64_TLSDESC_CALL

Also some Init-Exec is optimized to Local-Exec if possible. They are:

 - R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21
 - R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC

Finally some Local-Exec relocation are handled in relocateOne:

 - R_AARCH64_TLSLE_ADD_TPREL_HI12
 - R_AARCH64_TLSLE_ADD_TPREL_LO12_NC

This work is mainly for compiler bootstrap, where static binaries is
showing good progress (although shared object still lacking support
from both TLS aarch64 backend and some other issues).

llvm-svn: 260677
2016-02-12 13:43:03 +00:00
Rui Ueyama 24b794e8aa Make compCtors strict weak ordering.
Previously, if both A and B are ".ctors", both compCtors(A, B) and
compCtors(B, A) are true, which is a violation of the strict weak
ordering because such function is not antisymmetric.

llvm-svn: 260633
2016-02-12 00:38:46 +00:00
Rui Ueyama 5af8368f8b ELF: Implement the correct semantics of .[cd]tors.
As I noted in the comment, the sorting order of .[cd]tors are
different from .{init,fini}_array's.

http://reviews.llvm.org/D17120

llvm-svn: 260620
2016-02-11 23:41:38 +00:00
Rui Ueyama f9de0d6904 ELF: Remove readLinkerScript and define LinkerScript::read instead.
llvm-svn: 260598
2016-02-11 21:38:55 +00:00
Rui Ueyama c1c282a04e ELF: Release Target at end of link().
Previously, Target held a value until a new value is assigned to the
variable. That was a benign leak -- that was not an unbounded leak
and didn't grab any resources except a small amount of memory. But
it is better to fix than leaving as is.

llvm-svn: 260592
2016-02-11 21:18:01 +00:00
Rui Ueyama 717677af35 ELF: Create LinkerScript class to move code out of Writer.
Previously, we had code for linker scripts in Writer. This patch
separates that as LinkerScript class. The class provides a few
functions to query linker scripts and is also a container of some
linker-script-specific information.

Hopefully, Writer will only implement the default behavior and let
the new class handle gotchas regarding linker scripts.

llvm-svn: 260591
2016-02-11 21:17:59 +00:00
Rafael Espindola 9d13d04138 Sort includes. NFC.
llvm-svn: 260528
2016-02-11 15:24:48 +00:00
George Rimar 2960c9867a [ELF] - Remove R_X86_64_GOTTPOFF from static relocation processing
R_X86_64_TPOFF64 is a dynamic relocation,
it should not appear in static relocation processing.
Patch fixes it.

Differential revision: http://reviews.llvm.org/D16880

llvm-svn: 260508
2016-02-11 11:14:46 +00:00
Rui Ueyama 6f46de21e1 ELF: Sort .[cd]tors by priority as we do for .{init,fini}_array.
llvm-svn: 260477
2016-02-11 01:07:19 +00:00
Rui Ueyama c2dca5d76e Reduce code repetition. NFC.
llvm-svn: 260476
2016-02-11 01:07:18 +00:00
Rui Ueyama 704da023cc Reorder code to improve readability. NFC.
llvm-svn: 260467
2016-02-10 23:43:16 +00:00
Rafael Espindola ef762f2639 Don't include NOBITS TLS in PT_LOAD.
They don't count for the memory or file size, so this is mostly just a
simplification.

The only noticeable difference should be fewer empty program headers.

llvm-svn: 260465
2016-02-10 23:29:38 +00:00
Rui Ueyama 2625882ebb ELF: Use stable sort to sort .{init,fini}_array sections.
Global constructors and destructors are guaranteed to be called
in the order as they appear in a translation unit. So we don't want
to mess up the order if they have the same priority.

llvm-svn: 260463
2016-02-10 23:26:27 +00:00
Rui Ueyama c418570db5 ELF: Implement __attribute__((init_priority(N)) support.
llvm-svn: 260460
2016-02-10 23:20:42 +00:00
Rafael Espindola 4fc6044a5e Split the creation of program headers in a few steps.
IMHO this makes the code easier to read and should help with linker
scripts.

This is strongly based on D16575. The main differences are:

We record a range of sections, not every section in a program header.

scanHeaders takes case of deciding what goes in every program header,
including PT_GNU_RELRO

We create dummy sections for the start of the file

With this, program header creation has 3 isolated stages:

Map sections to program headers.
Assign addresses to *sections*
Looking at sections find the address and size of each program header.

Thanks to George Rimar for the initial version.

llvm-svn: 260453
2016-02-10 22:43:13 +00:00
Rui Ueyama d41cb95621 ELF: Combine cases that has the same code.
llvm-svn: 260444
2016-02-10 22:00:21 +00:00
Simon Atanasyan 2287dc3bf8 [ELF][MIPS] Add lazy relocation support for MIPS
The patch adds lazy relocation support for MIPS and R_MIPS_26 relocation
handing.

R_MIPS_26 relocation might require PLT entry creation. In that case it
is fully supported by the patch. But if the relocation target is a local
symbol we need to use a different expression to calculate the relocation
result. This case is not implemented yet because there is no method to
get know the kind of relocation target in the `relocateOne` routine.

Differential Revision: http://reviews.llvm.org/D16982

llvm-svn: 260424
2016-02-10 19:57:19 +00:00
Rafael Espindola 96449907a5 Add support for R_X86_64_DTPOFF64.
It is used by clang to produce debug info for tls variables.

llvm-svn: 260384
2016-02-10 16:26:31 +00:00
Rafael Espindola 156ed8ddd7 Use a SymbolBody to represent the personality.
NFC, just more in line with the rest of lld.

Thanks to Rui for the suggestion.

llvm-svn: 260380
2016-02-10 13:19:32 +00:00
Simon Atanasyan eae66c019b [ELF][MIPS] Group and sort initialization of MipsTargetInfo class fields. NFC
llvm-svn: 260365
2016-02-10 10:08:39 +00:00
Simon Atanasyan 6231391fa7 [ELF][MIPS] Rename MipsTargetInfo::relocateOne argument SA to S
MIPS 32-bit ABI uses REL relocation record format. We read addends from
relocation destinations right in the MipsTargetInfo::relocateOne
function.

llvm-svn: 260364
2016-02-10 10:08:35 +00:00
Rui Ueyama d3bd97a97d Rangefy, and replace a switch with `if`s. NFC.
llvm-svn: 260320
2016-02-09 23:11:21 +00:00
Rafael Espindola 9e072d30e5 Fix inverted comparison.
llvm-svn: 260310
2016-02-09 22:47:34 +00:00
Rui Ueyama dbcfedb330 ELF: Add 'using namespace llvm::dwarf'.
Most constants defined in llvm::dwarf namespace start with "DW_".
We don't have to worry about name conflicts.

llvm-svn: 260297
2016-02-09 21:46:11 +00:00
Rui Ueyama 6448f8ae5d ELF: Add .eh_frame 'P', 'R' and 'L' augmentation characters.
This basically reverts commit r260073 because it is found that
augmentation strings don't always start with "zR". It is reported
as https://llvm.org/bugs/show_bug.cgi?id=26541.

llvm-svn: 260294
2016-02-09 21:41:01 +00:00
Rafael Espindola a0a65f973a Use the plt entry as the address of some symbols.
This is the function equivalent of a copy relocation.

Since functions are expected to change sizes, we cannot use copy
relocations. In situations where one would be needed, what is done
instead is:
* Create a plt entry
* Output an undefined symbol whose addr is the plt entry.

The dynamic linker makes sure any shared library uses the plt entry as
the function address.

llvm-svn: 260224
2016-02-09 15:11:01 +00:00
Rafael Espindola a64f7d1148 Fix the alignment of PT_PHDR.
We were claiming it was aligned to 8 bytes even on 32 bit files, which
is not the case.

llvm-svn: 260102
2016-02-08 15:33:53 +00:00
Simon Atanasyan e1bfc2e793 [ELF][MIPS] Support R_MIPS_COPY relocation
Generate R_MIPS_COPY relocation for 'static' relocations against object
symbols defined in a shared libraries.

llvm-svn: 260083
2016-02-08 10:05:13 +00:00
Rui Ueyama be748c2033 ELF: Simplify getFdeEncoding.
I found that the handling of 'L' character in an augmentation string is
wrong because 'L' means that the next byte is the length field. I could
have fixed that by just skipping the next byte, but I decided to take a
different approach.

Teaching the linker about all the types of CIE internal records just to
skip them is silly. And the code doing that is not actually executed now
(that's why the bug did not cause any issue.) It is because the 'R' field,
which we want to read, is always at beginning of the CIE. So I reduced
the code dramatically by assuming that that's always the case. I want to
see how it works in the wild. If it doesn't work, we can roll this back
(with a fix for 'L').

http://reviews.llvm.org/D16939

llvm-svn: 260073
2016-02-08 05:18:44 +00:00
Simon Atanasyan b76108a63a [ELF][MIPS] Add comments to describe __gnu_local_gp magic symbol
NFC. Follow-up to r259781.

llvm-svn: 260027
2016-02-07 12:09:40 +00:00
Rafael Espindola d0078b2dba Sort headers. NFC.
llvm-svn: 259959
2016-02-06 00:06:26 +00:00
Rui Ueyama 1b45cca6d7 ELF: Simplify readEntryLength.
I removed "CIE/FIE size is too large" error because that was not
checking for correct error conditions. [UINT_MAX - 4, UINT_MAX) is
a correct range as a size of a CIE/FDE record. It's just that the
size cannot be larger than the section size.

llvm-svn: 259951
2016-02-05 23:24:05 +00:00
Rui Ueyama c0c92609c4 ELF: Make EHOutputSection::readEntryLength a non-member function.
This function did not use any fields of the class.

llvm-svn: 259946
2016-02-05 22:56:03 +00:00
Rafael Espindola 95708931cf Fix PT_GNU_RELRO computation.
We were not including TLS sections.

llvm-svn: 259945
2016-02-05 22:55:06 +00:00
Rui Ueyama 5a0b2f75db Simplify. NFC.
llvm-svn: 259903
2016-02-05 19:13:18 +00:00
Rui Ueyama 4197a6ab1b ELF: Make Out<ELFT> initialization less error-prone.
Previously, it was easy to leave some Out<ELFT> fields uninitialized
because assignments to the fields are mixed with output section
instantiations. In this patch, I separate initializations from assignments
to improve readability.

http://reviews.llvm.org/D16864

llvm-svn: 259899
2016-02-05 18:41:40 +00:00
Rafael Espindola abebed982a Rename IsUsedInDynamicReloc to MustBeInDynSym.
The variable was marking various cases where a symbol must be included
in the dynamic symbol table. Being used by a dynamic relocation was only
one of them.

llvm-svn: 259889
2016-02-05 15:27:15 +00:00
Rafael Espindola d30eb7d77d Centralize most calls to setUsedInDynamicReloc.
llvm-svn: 259887
2016-02-05 15:03:10 +00:00
Rui Ueyama 0e53c7dd2c ELF: Make names for TLS module indices shorter.
The previous names contained "Local" and "Current", but what we
are handling is always local and current, so they were redundant.

TlsIndex comes from "tls_index" struct that Ulrich Drepper is using
in this document to describe this data structure in GOT.

llvm-svn: 259852
2016-02-05 00:10:02 +00:00
Rui Ueyama 812293ae1d Simplify. NFC.
llvm-svn: 259848
2016-02-04 23:39:35 +00:00
Rui Ueyama 8e47eba9fd Do not round uintX_t to uint32_t.
On 64-bit computers, this value can be larger than UINT32_MAX.

llvm-svn: 259847
2016-02-04 23:39:33 +00:00
Rui Ueyama f9cec37880 Merge conditions of two nested `if`s.
llvm-svn: 259843
2016-02-04 23:18:22 +00:00
Sean Silva 09247f8955 Don't push relocation sections onto InputSection<ELFT>::Discarded.RelocSections
Summary:
LLVM3.3 (and earlier) would fail to include a relocation section in
the group that the section it was relocating is in. Object files
affected by this issue have been encountered in the wild when using LLD.

This would result in a siutation like:

  Section {
    Index: 5
    Name: .text._Z3fooIiEvv (6)
    Type: SHT_PROGBITS (0x1)
    Flags [ (0x206)
      SHF_ALLOC (0x2)
      SHF_EXECINSTR (0x4)
      SHF_GROUP (0x200)
    ]
    Address: 0x0
    Offset: 0x48
    Size: 5
    Link: 0
    Info: 0
    AddressAlignment: 1
    EntrySize: 0
  }
  Section {
    Index: 6
    Name: .rela.text._Z3fooIiEvv (1)
    Type: SHT_RELA (0x4)
    Flags [ (0x0)
    ]
    Address: 0x0
    Offset: 0x3F0
    Size: 24
    Link: 8
    Info: 5
    AddressAlignment: 8
    EntrySize: 24
  }

In LLD, during symbol resolution, we discard the section containing the
weak symbol, but this amounts to replacing it with
InputSection<ELFT>::Discarded.
When we later saw the corresponding relocation section, we would then
end up pusing onto InputSection<ELFT>::Discarded.RelocSections, which is
bogus.

Reviewers: ruiu, rafael

Subscribers: llvm-commits, Bigcheese

Differential Revision: http://reviews.llvm.org/D16898

llvm-svn: 259831
2016-02-04 21:41:07 +00:00
Rafael Espindola de9857e3c1 Avoid code duplication when creating dynamic relocations.
Another case where we currently have almost duplicated code is the
creation of dynamic relocations. First to decide if we need one, then to
decide what to write.

This patch fixes it by passing more information from the relocation scan
to the section writing code. This is the same idea used for r258723.

I actually think it should be possible to simplify this further by
reordering things a bit in the writer. For example, we should be able to
represent almost every position in the file with an OutputSeciton and
offset. When writing it out we then just need to add the offset to the
OutputSection VA.

llvm-svn: 259829
2016-02-04 21:33:05 +00:00
Simon Atanasyan e364e2e9ce [ELF][MIPS] Support R_MIPS_PC32 relocation handling
llvm-svn: 259782
2016-02-04 12:31:39 +00:00
Simon Atanasyan 597df21eb2 [ELF][MIPS] Add handling for __gnu_local_gp symbol
This symbol is a "fake" symbol like "_gp_disp" and denotes
the GOT + 0x7FF0 value.

llvm-svn: 259781
2016-02-04 12:09:49 +00:00
Simon Atanasyan 4b03451cac [ELF][MIPS] Replace needsMipsLocalGot function by canBePreempted
Symbol does not need an entry i the 'global' part of GOT if it cannot be
preempted. So canBePreempted fully satisfies us at least for now.

llvm-svn: 259779
2016-02-04 11:51:45 +00:00
Simon Atanasyan 170356ba32 [ELF][MIPS] Always create global GOT entry for symbols defined in DSO
If relocation against symbol requires GOT entry creation and this symbol
is defined in DSO, the GOT entry should be created in the 'global' part
of the GOT even if we link executable file. Also we do not need to create
a dynamic symbol table entry for global symbol corresponding to the
local GOT entry.

llvm-svn: 259778
2016-02-04 11:51:39 +00:00
Rafael Espindola 9e3f84bf95 Fix addend computation for IRELATIVE relocations.
llvm-svn: 259692
2016-02-03 21:02:48 +00:00
Rui Ueyama c2d2f44683 ELF: Remove dead code.
R_X86_64_DTPOFF64 relocs are for the dynamic linker.
Static linkers create them but don't consume them.

llvm-svn: 259679
2016-02-03 19:07:56 +00:00
Rafael Espindola 38a36c4f1c Simplify. NFC.
llvm-svn: 259660
2016-02-03 16:53:39 +00:00
Rui Ueyama 512c61df1c Define SymbolBody::getSize instead of getSymSize(SymbolBody&). NFC.
llvm-svn: 259613
2016-02-03 00:12:24 +00:00
Rui Ueyama b87be6c327 ELF: Write about the current policy to README.
llvm-svn: 259606
2016-02-02 23:45:54 +00:00
Rui Ueyama b6940115a8 ELF: Make link() to take an output stream to which error messages are written.
http://reviews.llvm.org/D16668

llvm-svn: 259597
2016-02-02 22:49:32 +00:00
Rui Ueyama cbe392629b ELF: Do not exit if it cannot open an output file.
It can fail to open an output file for various reasons, including
lack of permission, too long filename, or the output file is not
a mmap'able file.

llvm-svn: 259596
2016-02-02 22:48:04 +00:00
Rui Ueyama 21eecb4f14 Re-submit ELF: Report multiple errors from the driver.
This reverts r259395 which reverted r259143.

llvm-svn: 259572
2016-02-02 21:13:09 +00:00
Rui Ueyama 025d59b16a ELF: Do not use fatal in LinkerScript.cpp.
This patch adds "Error" field to LinkerScript class. That field
is false by default, and set to true if there is a syntax error
in an input file. The linker script parser is a recursive-descedent
parser. Each function returns if Error is true -- so that
eventually the whole parser returns to a caller.

http://reviews.llvm.org/D16667

llvm-svn: 259557
2016-02-02 20:27:59 +00:00
Rui Ueyama 8a789e0204 ELF: Use StringRef instead of std::string.
All MemoryBuffers for archive files are guaranteed to exist as long
as their children are used in the linker. So we don't need to copy
strings here. Thanks to Sean Silva for pointing this out.

llvm-svn: 259554
2016-02-02 20:24:31 +00:00
Rafael Espindola 0df1b0bf42 Expand comment a bit.
I have spent some time prototyping this idea. While it seems to work, I
now think it is probably not worth it.

llvm-svn: 259516
2016-02-02 15:45:37 +00:00
George Rimar 5c36e5938d [ELF] Implemented -Bsymbolic-functions command line option
-Bsymbolic-functions: 
When creating a shared library, bind references to global 
function symbols to the definition within the shared library, if any.

This patch also fixed behavior of already existent -Bsymbolic:
previously PLT entries were created even if -Bsymbolic was specified.

Differential revision: http://reviews.llvm.org/D16411

llvm-svn: 259481
2016-02-02 09:28:53 +00:00
Simon Atanasyan 21b473d490 [ELF] Remove redundant empty line. NFC
llvm-svn: 259479
2016-02-02 09:08:04 +00:00
Simon Atanasyan 40d25f3358 [ELF] Finalize .dynamic section at the end
Some dynamic table tags like RELSZ and PLTRELSZ depens on result of
finalizing corresponding relocation sections. Therefore we have to
finalize .dynamic section at the end.

Differential Revision: http://reviews.llvm.org/D16799

llvm-svn: 259478
2016-02-02 09:07:47 +00:00
Rui Ueyama 71c066d8cf ELF: Include archive names in error messages.
If object files are drawn from archive files, the error message should
be something like "conflict symbols in foo.a(bar.o) and baz.o" instead
of "conflict symbols in bar.o and baz.o". This patch implements that.

llvm-svn: 259475
2016-02-02 08:22:41 +00:00
Rui Ueyama 82b4288b1a ELF: Simplify and add comments.
llvm-svn: 259474
2016-02-02 07:50:18 +00:00
Rui Ueyama 05aecba118 Do not use "No" prefix for boolean variables to make it simpler. NFC.
llvm-svn: 259472
2016-02-02 07:18:15 +00:00
Rui Ueyama f263c4b0f1 ELF: Move GOT relocation handler code to one place. NFC.
llvm-svn: 259471
2016-02-02 07:07:35 +00:00
Rui Ueyama 554f273b9d ELF: Move PLT relocation handler to one place. NFC.
llvm-svn: 259470
2016-02-02 07:07:34 +00:00
Rui Ueyama 343f7e5d8d ELF: Move GNU_IFUNC relocation handler to one place. NFC.
llvm-svn: 259468
2016-02-02 06:29:10 +00:00
Rui Ueyama 6d3874b995 ELF: Move copy relocation handler to one place. NFC.
llvm-svn: 259467
2016-02-02 06:08:08 +00:00
Rui Ueyama 1ac1338ac8 ELF: Move code for MIPS local GOT entries to one place. NFC.
llvm-svn: 259466
2016-02-02 05:55:28 +00:00
Rui Ueyama 909cc68163 Add comments.
llvm-svn: 259460
2016-02-02 03:11:27 +00:00
Rui Ueyama 74937fcd00 Update a comment.
llvm-svn: 259458
2016-02-02 02:53:58 +00:00
Rui Ueyama 5cbf5d207a Replace auto with the real type.
llvm-svn: 259455
2016-02-02 02:29:03 +00:00
Rui Ueyama cdb7882cb2 Always initialize Out<ELFT> members.
Instead of leave unused fields as is, set them to nullptr.
Currnetly this is NFC, but if you call writeResults more than
once, you should be able to see the difference.

llvm-svn: 259444
2016-02-02 00:35:49 +00:00
Rui Ueyama 21923996f8 ELF: Do not call fatal() if relocation contraints are not satisfied.
http://reviews.llvm.org/D16648

llvm-svn: 259435
2016-02-01 23:28:21 +00:00
Rafael Espindola 4d91f7fc25 Simplify.
Now that we remember the StringRefs when they are first added, we can
write the table in any order.

llvm-svn: 259417
2016-02-01 21:52:00 +00:00
Rui Ueyama b5a6970ace ELF: Teach SymbolBody about how to get its addresses.
Previously, the methods to get symbol addresses were somewhat scattered
in many places. You can use getEntryAddr returns the address of the symbol,
but if you want to get the GOT address for the symbol, you needed to call
Out<ELFT>::Got->getEntryAddr(Sym). This change adds new functions, getVA,
getGotVA, getGotPltVA, and getPltVA to SymbolBody, so that you can use
SymbolBody as the central place to ask about symbols.

http://reviews.llvm.org/D16710

llvm-svn: 259404
2016-02-01 21:00:35 +00:00
Nico Weber f07bd3b72d Revert r259143, it broke check-lld on Windows (see PR26388).
llvm-svn: 259395
2016-02-01 20:03:53 +00:00
Rui Ueyama 3c8d049d88 Move template instantiations to end of the file.
llvm-svn: 259276
2016-01-29 23:59:15 +00:00
Rui Ueyama cf375935a9 Update comments about the entries in .got.plt.
The original comments were a bit inaccurate because there was no 4 addends.

llvm-svn: 259274
2016-01-29 23:58:03 +00:00
Rui Ueyama 8364c6269a Add comments on a mysterious value in MIPS GOT[1].
Thanks to Simon Atanasyan and Igor Kudrin for describing the code!

llvm-svn: 259259
2016-01-29 22:55:38 +00:00
Rui Ueyama 5e378ddc1e Consistenly use sizeof(uintX_t) instead of ELFT::Is64Bits ? 8 : 4.
llvm-svn: 259250
2016-01-29 22:18:57 +00:00
Rui Ueyama ead75fc84f Add comments.
llvm-svn: 259249
2016-01-29 22:18:55 +00:00
Rui Ueyama 65d98ea473 Replace code duplications with function calls.
llvm-svn: 259238
2016-01-29 20:31:05 +00:00
Rui Ueyama 16ba669c87 ELF: Report duplicate symbols as many as possible instead of the first one.
http://reviews.llvm.org/D16647

llvm-svn: 259233
2016-01-29 19:41:13 +00:00
George Rimar 2c9b7bd326 Replace StringRef with std::string in LinkerDriver::addLibrary(StringRef Name) because std::string is destroyed after assigning what fills the buffer with garbage and StringRef is no more valid.
That fixes few failing tests under windows+msvs2015(debug).

llvm-svn: 259186
2016-01-29 10:52:52 +00:00
Rui Ueyama 9398f86a2a Remove a parameter from Target::writePlt.
llvm-svn: 259158
2016-01-29 04:15:02 +00:00
Rui Ueyama 012eb783b3 ELF: Provide default implemenatations for simple functions.
llvm-svn: 259157
2016-01-29 04:05:09 +00:00
Rui Ueyama 57b676c546 Define stub functions instead of pure virtual functions.
To remove empty functions.

llvm-svn: 259155
2016-01-29 03:51:51 +00:00
Rui Ueyama 900e2d2578 ELF: Do not pass addresses that can be obtained using Out.
llvm-svn: 259154
2016-01-29 03:51:49 +00:00
Rui Ueyama 6251545683 Rename PltZeroEntrySize -> PltZeroSize.
This patch also fixes parameter name. They points to the beginning
of PLT or GOT tables, so GotAddr or PltAddr are better.)

llvm-svn: 259150
2016-01-29 03:00:32 +00:00
Rui Ueyama 69c30edb5e Add a comment.
llvm-svn: 259149
2016-01-29 03:00:30 +00:00
Rui Ueyama c516ae1719 ELF: Make Target's member function names shorter.
llvm-svn: 259147
2016-01-29 02:33:45 +00:00
Rui Ueyama c112c1be69 Rename includeInDynamicSymtab -> includeInDynsym.
llvm-svn: 259144
2016-01-29 02:17:01 +00:00
Rui Ueyama 1940424632 ELF: Report multiple errors from the driver.
This patch let the driver keep going until it parses all
command line options.

http://reviews.llvm.org/D16645

llvm-svn: 259143
2016-01-29 01:54:52 +00:00
Rui Ueyama 572a6f74a7 Rename DynamicSymbolTableIndex -> DynsymIndex.
This is the index in .dynsym, so the new name should make sense.

llvm-svn: 259142
2016-01-29 01:49:33 +00:00
Rui Ueyama 724d625c7a ELF: Remove accessors from Target.
These accessors do not provide values. We can simply make the variables public.

llvm-svn: 259141
2016-01-29 01:49:32 +00:00
Rui Ueyama 74b7df016f Remove unused variable.
llvm-svn: 259140
2016-01-29 01:49:29 +00:00