Commit Graph

3293 Commits

Author SHA1 Message Date
Rafael Espindola b597408da4 Simplify parseMemberFiles to take a single file.
llvm-svn: 235751
2015-04-24 19:08:51 +00:00
Rafael Espindola 773a159116 Simplify now that there is only one file. NFC.
llvm-svn: 235747
2015-04-24 19:01:30 +00:00
Rafael Espindola ab5696ba82 Return ErrorOr<std::unique_ptr<File>>. NFC.
llvm-svn: 235744
2015-04-24 18:51:30 +00:00
Rafael Espindola c1d535af05 Remove unused enum value. NFC.
llvm-svn: 235742
2015-04-24 18:36:57 +00:00
Rafael Espindola dedab912c3 Return an ErrorOr<std::unique_ptr<File>>. NFC.
llvm-svn: 235741
2015-04-24 18:33:50 +00:00
Davide Italiano 75e1172b19 [Test] Explictly pass target architecture.
If we're not being explicit, the test fails on windows.
Reported and tested by Aaron Ballman!

llvm-svn: 235739
2015-04-24 18:18:34 +00:00
Rafael Espindola c08ab8e6e4 Delete unnecessary generality in loadFile.
loadFile could load mulitple files just because yaml has a feature for
putting multiple documents in one file.

Designing a linker around what yaml can do seems like a bad idea to
me. This patch changes it to read a single file.

There are further improvements to be done to the api and they
will follow shortly.

llvm-svn: 235724
2015-04-24 15:51:45 +00:00
Simon Atanasyan e10a258527 [Mips] Simplify the code a bit using early return
No functional changes.

llvm-svn: 235708
2015-04-24 11:14:24 +00:00
Denis Protivensky 87d935dd09 [ARM] Update TODO notes
llvm-svn: 235706
2015-04-24 09:55:11 +00:00
Denis Protivensky c3431bf67b [ARM] Implement R_ARM_COPY relocation
This adds support of copying objects from shared libraries.

llvm-svn: 235705
2015-04-24 08:53:02 +00:00
Leny Kholodov 592cee666e [ARM] Update R_ARM_TARGET1 command line option names (remove prefix 'arm-')
Command line options --arm-target1-rel and --arm-target1-abs have been renamed to be compatible with GNU linkers.
Two tests have been updated:
  test/elf/options/target-specific-args.test
  test/elf/ARM/rel-arm-target1.test

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

llvm-svn: 235499
2015-04-22 11:58:09 +00:00
Leny Kholodov 9e4292c0ec [ARM] Replace branches to undefined weak functions with NOP
According to the code model (ARM, Thumb, Thumb2) this patch updates the b/bl/blx 0 instructions with NOP.
test/elf/ARM/weak-branch.test has been added with tests for all available NOP (A1, T1, T2 encodings).

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

llvm-svn: 235498
2015-04-22 11:47:53 +00:00
Simon Atanasyan 6668eb3c40 [Mips] Assign .MIPS.options section to the PT_LOAD segment
llvm-svn: 235488
2015-04-22 08:09:38 +00:00
Simon Atanasyan 5606dac67e [ELF] Allow TargetLayout descendants to control assignment sections to segments
The TargetLayout class puts two sections into the same segment if they
have equal segment types and the same section flags (SHF_xxx). To be
able to merge some sort of sections into the same segment we drop some
flags before comparison. For example to merge string sections into Data
segment we drop SHF_STRINGS and SHF_MERGE flags.

The patch allows TargetLayout descendants to drop some target specific
section flags. MIPS target needs that to merge .MIPS.options section
which has SHF_MIPS_NOSTRIP flag into the LOAD segment.

http://reviews.llvm.org/D9160

llvm-svn: 235487
2015-04-22 07:57:35 +00:00
Denis Protivensky 4b0abddeea [ARM] Implement veneers for dynamic executable linking
llvm-svn: 235486
2015-04-22 07:51:26 +00:00
Denis Protivensky f6c8938edd [ARM] Move veneer generators to base class. NFC
llvm-svn: 235485
2015-04-22 07:45:55 +00:00
Denis Protivensky 38b09f529c [ARM] Rename static veneer atoms to absolute code veneer atoms
No functional changes.

llvm-svn: 235484
2015-04-22 07:38:47 +00:00
Simon Atanasyan acd58af7df [ELF] Change return type of the OutputSection::flags() method
This method returns _flags field which has `uint64_t` type. Now the
field's type and the method's return type are consistent.

llvm-svn: 235393
2015-04-21 17:02:49 +00:00
Simon Atanasyan 72026b013b [ELF] Narrow down the type of OutputSection::_sections container
The `OutputSection::appendSection()` method always gets a pointer
to the `Section` class descendants. So it is not necessary to keep them
in the vector of `Chunk` pointers.

No functional changes.

llvm-svn: 235392
2015-04-21 17:02:42 +00:00
Simon Atanasyan fcb19e19d0 [Mips] Write .reginfo section into the separate PT_MIPS_REGINFO segment
llvm-svn: 235391
2015-04-21 17:02:35 +00:00
Simon Atanasyan d64f8a5188 [ELF] Simplify class memeber function declaration
No functional changes.

llvm-svn: 235390
2015-04-21 17:02:27 +00:00
Davide Italiano 037cfdd1db --discard-locals should be --discard-all here.
Sorry for the mistake/confusion.

llvm-svn: 235359
2015-04-20 22:54:50 +00:00
Davide Italiano 30326b9d8f [GNU/ELF] Add support for -X/--discard-locals.
There's (almost) never need to keep .L symbols around for production
builds. In fact, the FreeBSD kernel explicitly specify -X beacuse the
size impact (and the subsequent performance impact) might be significant,
because we keep symbols in memory.
I was tempted to make this the default, but I haven't (yet).

PR:		23232
llvm-svn: 235357
2015-04-20 22:52:56 +00:00
Simon Atanasyan 84adf3ff15 [Mips] Write DT_MIPS_OPTIONS tag to .dynamic section
If .MIPS.options section exists the DT_MIPS_OPTIONS tag should hold
an address of this section.

llvm-svn: 235290
2015-04-20 07:36:27 +00:00
Simon Atanasyan 8119228977 [Mips] Support R_MICROMIPS_PC18_S3/PC19_S2/PC21_S2/PC26_S2 relocations handling
llvm-svn: 235289
2015-04-20 07:34:52 +00:00
Simon Atanasyan 41ce98cc6f [Mips] Support R_MICROMIPS_GOT_DISP / PAGE / OFST relocations handling
llvm-svn: 235288
2015-04-20 07:33:02 +00:00
Davide Italiano 3d9e582a46 Accept --dynamic-linker <file>.
Before we only accepted --dynamic-linker=<file> and -dynamic-linker <file>
but older versions of GNU ld (e.g. 2.17.50) accept this other form, so
try to be compatible.

PR:		23233
llvm-svn: 235282
2015-04-19 23:45:41 +00:00
Davide Italiano 9a5b990f27 [GNU/ELF] Add support for -x/--discard-all.
PR:		23232
llvm-svn: 235247
2015-04-18 00:32:38 +00:00
Rui Ueyama e47aca8a6c Delete dead code (again).
llvm-svn: 235217
2015-04-17 18:58:34 +00:00
Rui Ueyama 3ff1170e5e Delete dead code.
llvm-svn: 235216
2015-04-17 18:54:29 +00:00
Rui Ueyama 1620a334ba Use C++11 non-static member initialization.
llvm-svn: 235187
2015-04-17 12:53:16 +00:00
Denis Protivensky 0575c5de68 [ARM] Implement R_ARM_TLS_IE32 for dynamic executable
llvm-svn: 235182
2015-04-17 11:30:29 +00:00
Denis Protivensky 3b5f7e9965 [ARM] Test R_ARM_TLS_LE32 for dynamic executable
llvm-svn: 235180
2015-04-17 11:24:11 +00:00
Simon Atanasyan 6313038925 [Mips] Make tests more tolerant to offsets, symbol sizes etc
No functional changes.

llvm-svn: 235035
2015-04-15 18:32:22 +00:00
Simon Atanasyan 09129d957c [Mips] clang-format the code
llvm-svn: 235033
2015-04-15 18:32:05 +00:00
Simon Atanasyan f4a87333ff [Mips] Remove redundant `.got` section lookup
No functional changes.

llvm-svn: 235032
2015-04-15 18:31:59 +00:00
Simon Atanasyan 834632cd1a [Mips] Create _GLOBAL_OFFSET_TABLE_ only if the .got section exists
llvm-svn: 235031
2015-04-15 18:31:53 +00:00
Simon Atanasyan fa21338a97 [Mips] Check `_gp_disp` symbol using a trivial string comparison
No functional changes.

llvm-svn: 235030
2015-04-15 18:31:44 +00:00
Adhemerval Zanella 17d33dc3ec ELF/Arch64: Fix testcases requirements
This patch fixes 2 aarch64 testcases that require dissassemble output
when running on builds that do not enable aarch64 backend.

llvm-svn: 235001
2015-04-15 12:03:42 +00:00
Denis Protivensky 0bcc491318 [ARM] Don't generate veneers when bl->blx fixup is possible
llvm-svn: 234991
2015-04-15 10:05:12 +00:00
Denis Protivensky 7f6b22ee84 [ARM] Pass Thumb flag to handler methods instead of atom
llvm-svn: 234989
2015-04-15 09:57:04 +00:00
Denis Protivensky 97375dc751 [ELF] Fix gcc -pedantic warnings (remove extra ';')
llvm-svn: 234981
2015-04-15 07:45:11 +00:00
Rui Ueyama bd94dbcf0a ELF: Attempt to simplify Segment::AssignVirtualAddress.
This is a retry of r234944.

llvm-svn: 234955
2015-04-14 23:11:14 +00:00
Rui Ueyama 13e41bcf9c temporary
llvm-svn: 234954
2015-04-14 23:11:12 +00:00
Rui Ueyama 0a57476c20 temporary
llvm-svn: 234953
2015-04-14 23:11:10 +00:00
Rui Ueyama ed796d518c ELF: Move Instrcution definition to HexagonEncoding.h.
HexagonEncodings.h contains a list of bitmasks. The file is used
only by HexagonRelocationHandler.cpp. The header is odd in the sense
that it uses struct Instruction but it doesn't define the data type.

This patch moves the struct definition to the header.

llvm-svn: 234947
2015-04-14 21:41:00 +00:00
Rui Ueyama ae9168b718 Revert "ELF: Attempt to simplify Segment::assignVirtualAddress()."
This reverts commit r234944 because it seems to have broken the buildbots.

llvm-svn: 234946
2015-04-14 21:38:39 +00:00
Rui Ueyama 5ec40d6e73 ELF: Attempt to simplify Segment::assignVirtualAddress().
This function is too long and complicated. Looks like new code was
added incrementaly without any refactoring. Maybe no one can describe
its exact semantics any more? It even contains copy-pastes inside it.

This patch is an (incomplete) attempt to simplify the function.
I tried to mechanically translate code to another form more intelligible.
I don't still understand the whole picture, but this patch shouldn't
change the linker's functionality.

llvm-svn: 234944
2015-04-14 21:20:37 +00:00
Davide Italiano b60453fe29 Rename ExecutableAtom.hpp to ExecutableAtom.h
This is for consistency with what's used elsewhere in lld tree.

llvm-svn: 234943
2015-04-14 21:06:56 +00:00
Rui Ueyama 921b8e93bb ELF: Remove redundant namespace qualifiers.
llvm-svn: 234938
2015-04-14 20:39:06 +00:00
Rui Ueyama 16d8e44da5 ELF: Simplify ELFDefinedAtom::contentType().
llvm-svn: 234936
2015-04-14 20:31:56 +00:00
Rui Ueyama 569e11af46 ELF: Split Atoms.h to Atoms.{h,cpp}.
llvm-svn: 234935
2015-04-14 20:21:53 +00:00
Rui Ueyama 2783469116 ELF: Split SegmentChunks.h to SegmentChunks.{h,cpp}.
llvm-svn: 234934
2015-04-14 20:12:50 +00:00
Rui Ueyama 06f70a087b ELF: Split HeaderChunks.h to HeaderChunks.{h,cpp}.
llvm-svn: 234932
2015-04-14 19:48:57 +00:00
Rui Ueyama befc11e007 ELF: Split SectionChunks.h to SectionChunks.{h,cpp}.
The size of AArch64TargetHander.cpp.o is now 4.1MB.

llvm-svn: 234931
2015-04-14 19:31:42 +00:00
Simon Atanasyan bdaab80160 [ELF] Use type helper Elf_Word instead of plain uint32_t data type
That helps to correctly write content of hash table if target and host
endianness are not the same. Right now that commit does not affect
any supported targets.

llvm-svn: 234928
2015-04-14 18:53:21 +00:00
Simon Atanasyan 1bd5d7e623 [ELF] Write whole std::vector using a single `memcpy` call
We do not need to iterate over `_buckets` and `_chains` vectors and
write all elements one by one.

No functional changes.

llvm-svn: 234927
2015-04-14 18:53:14 +00:00
Simon Atanasyan c0c4664618 [ELF] Remove redundant type cast to `char*` before passing array to memcpy
No functional changes.

llvm-svn: 234926
2015-04-14 18:53:09 +00:00
Simon Atanasyan 23025c812e [Mips] Write _DYNAMIC symbol on MIPS targets
llvm-svn: 234925
2015-04-14 18:53:03 +00:00
Simon Atanasyan dd6f1aaa73 [Mips] Make tests more tolerant to the program and section headers offsets
No functional changes.

llvm-svn: 234924
2015-04-14 18:52:55 +00:00
Rui Ueyama a852744a6a ELF: Split OutputELFWriter.h to OutputELFWriter.{h,cpp}.
The size of AArch64TargetHandler.cpp.o is now 4.5MB.

llvm-svn: 234916
2015-04-14 18:14:07 +00:00
Rui Ueyama 9d6ca7e272 ELF: Split TargetLayout.h into TargetLayout.{h,cpp}.
This patch makes AArch64TargetHandler.cpp.o from 8.5MB to 6.8MB.

llvm-svn: 234914
2015-04-14 18:04:57 +00:00
Rui Ueyama cfeb2512fd ELF: Remove ELFT template argument when referring the base class.
We don't need to repeat the template argument. They are not
ambiguous. MIPS is parameterized for ELFT, so we can't do this
for MIPS, though.

llvm-svn: 234913
2015-04-14 17:32:13 +00:00
Rui Ueyama 5557a0e688 Attempt to fix MSVC warning.
This patch tries to fix the following MSVC warning.

  warning C4661: 'bool
  lld:🧝:ELFFile<lld:🧝:ELF32LE>::isCompatible(unsigned
  char,unsigned char)' : no suitable definition provided for explicit
  template instantiation request

llvm-svn: 234909
2015-04-14 17:12:32 +00:00
Denis Protivensky 8f82dff193 [ARM] Implement mapping symbols for PLT0 entry
llvm-svn: 234876
2015-04-14 09:33:04 +00:00
Denis Protivensky 72a7581743 [ARM] Move out mapping atom functionality to a separate class
llvm-svn: 234874
2015-04-14 09:11:05 +00:00
Denis Protivensky e80fd18b45 [ARM] Rename IFUNC-related tests
llvm-svn: 234873
2015-04-14 08:44:55 +00:00
Denis Protivensky 4c895b189a [ARM] Improve IFUNC PLT test
llvm-svn: 234872
2015-04-14 08:40:02 +00:00
Rui Ueyama ff499469e0 Simplify short switch-cases.
llvm-svn: 234869
2015-04-14 07:19:29 +00:00
Rui Ueyama 707504e0f2 Remove excessive parentheses.
llvm-svn: 234868
2015-04-14 07:09:05 +00:00
Rui Ueyama bf138134b0 ELF: Remove a header which is used only by one .cpp file.
The data and the inline function defined in the header is used only
by HexagonRelocationHandler.cpp.

llvm-svn: 234867
2015-04-14 07:09:03 +00:00
Rui Ueyama 92259f7fa3 Fix indentation.
llvm-svn: 234866
2015-04-14 06:58:48 +00:00
Rui Ueyama 76dff95a98 ELF: Fix odd initialization code.
llvm-svn: 234865
2015-04-14 06:58:47 +00:00
Rui Ueyama 25f9b4b752 temporary
llvm-svn: 234864
2015-04-14 06:58:45 +00:00
Rui Ueyama f9fffa7e11 ELF: Move function definitions from .h to .cpp.
llvm-svn: 234863
2015-04-14 06:47:06 +00:00
Rui Ueyama 2f43dbec0a ELF: Inline ELFReader typedefs which are used only once.
llvm-svn: 234862
2015-04-14 06:22:53 +00:00
Rui Ueyama f3691620da ELF: Make common strings file-scoped constants.
llvm-svn: 234861
2015-04-14 06:08:07 +00:00
Rui Ueyama f505ccf451 ELF: Make ARMELFMappingAtom a non-template class.
llvm-svn: 234860
2015-04-14 05:21:26 +00:00
Rui Ueyama da3a9a1b0b ELF: Remove this-> as much as we can.
These this-> are there because their classes were templated.
They are no longer templated.

llvm-svn: 234859
2015-04-14 05:14:49 +00:00
Rui Ueyama 4caff31217 ELF: Remove ELFT parameter from ARMELFFile.
llvm-svn: 234858
2015-04-14 05:14:46 +00:00
Rui Ueyama ff8bc5680a ELF: Make HexagonFile a non-template class.
llvm-svn: 234857
2015-04-14 05:14:44 +00:00
Rui Ueyama 3996563428 Remove dead code.
llvm-svn: 234854
2015-04-14 04:54:01 +00:00
Rui Ueyama 7bda84d25e ELF: Remove ELFT and LinkingContext template parameters from ELFReader.
Previously, ELFReader takes three template arguments: EFLT,
LinkingContextT and FileT. FileT is itself templated.
So it was a bit complicated. Maybe too much.

Most architectures don't actually need to be parameterized for ELFT.
For example, x86 is always ELF32LE and x86-64 is ELF64LE.
However, because ELFReader requires a ELFT argument, we needed
to parameterize a class even if not needed.

This patch removes the parameter from the class. So now we can
de-templatize such classes (I didn't do that in this patch, though).

This patch also removes ContextT parameter since it didn't have to be
passed as a template argument.

llvm-svn: 234853
2015-04-14 04:53:57 +00:00
Rui Ueyama e75e50c045 Define make_dynamic_error_code(const char *).
The function took either StringRef or Twine. Since string literals are
ambiguous when resolving the overloading, many code calls used this
function with explicit type conversion. That led awkward code like
make_dynamic_error_code(Twine("Error occurred")).

This patch adds a function definition for string literals, so that
you can directly call the function with literals.

llvm-svn: 234841
2015-04-14 02:34:09 +00:00
Rui Ueyama 18783cea3f ELF: Remove almost empty class.
llvm-svn: 234834
2015-04-14 01:15:43 +00:00
Rui Ueyama 97d30b87f3 Remove unused variable.
llvm-svn: 234831
2015-04-14 01:10:19 +00:00
Rui Ueyama a5b6859ac4 ELF: Use less templates for ELF types.
These classes are templated but actually instantiated for only
one ELF type.

llvm-svn: 234830
2015-04-14 00:59:04 +00:00
Rui Ueyama ad87e54f1a ELF: Define ELF{32,64}{LE,BE} types and use them everywhere.
llvm-svn: 234823
2015-04-14 00:31:28 +00:00
Rui Ueyama d610a96d15 ELF: Remove useless templates that takes always the same ELF type.
llvm-svn: 234820
2015-04-14 00:08:09 +00:00
Rui Ueyama 243226852f ELF: Fix headers including each other.
HexagonSectionChunks.h and HexagonTargetHandler.h include each other.
This patch removes the former and merge it with the latter.

llvm-svn: 234817
2015-04-13 23:47:53 +00:00
Rui Ueyama 4bd8ece689 ELF: Move definitions from {Dynamic,ELF}File.h to .cpp files.
DynamicFile and ELFFile are instantiated for four different types,
ELF{32,64}{BE,LE}. Because the classes are instantiated in each
compilation unit, including the header file makes object files
10MB larger.

On Windows, issue of excessive template instantiation is critical,
since the regular COFF file supports only up to 65534 sections.
(We could use the extended COFF file format, but generating that
much COMDAT sections is not a good thing in the first place
because it means long compile time and long link time.)

I confirmed that this change makes AArch64TargetHandler.cpp.o
from 21MB to 8.5MB. It feels still too large, but I think it's
a good start.

llvm-svn: 234808
2015-04-13 22:52:11 +00:00
Rui Ueyama fa92b4c9d8 ELF: Simplify alignment check. NFC.
llvm-svn: 234791
2015-04-13 20:04:50 +00:00
Rui Ueyama cfba8b3481 ELF: s/ELFTy/ELFT/ for consistency.
llvm-svn: 234790
2015-04-13 20:04:48 +00:00
Rui Ueyama 3245a395c1 Remove else after return.
llvm-svn: 234784
2015-04-13 19:56:08 +00:00
Rui Ueyama 09dfd2544e Fix formatting and remove excessive parentheses.
llvm-svn: 234781
2015-04-13 19:24:00 +00:00
Simon Atanasyan 44e904581d [Mips] Rollback explicit instantiation of MipsELFFile template class
This is a follow-up to r234728 and r234729. It looks like explicit
instantiation of `MipsELFFile` is redundant and triggers Visual C++ warning.

llvm-svn: 234756
2015-04-13 15:32:42 +00:00
Adhemerval Zanella cced470374 ELF/Aarch64: Add overflow checks for relocation writes
This patch adds support for overflow checking when processing
R_AARCH64_CALL26, R_AARCH64_JUMP26, R_AARCH64_CONDBR19,
R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21, and R_AARCH64_TLSLE_ADD_TPREL_HI12
relocations.

llvm-svn: 234749
2015-04-13 12:14:14 +00:00
Adhemerval Zanella b79cea9180 ELF/AArch64: Add tests for ADR_PREL_LO21
Add default and overflow checking when processing
R_AARCH64_ADR_PREL_LO21 relocations.

llvm-svn: 234747
2015-04-13 12:11:23 +00:00
Adhemerval Zanella 0c2f3bcd67 [PATCH 08/10] ELF/Aarch64: Add R_AARCH64_ADR_GOT_PAGE and R_AARCH64_LD64_GOT_LO12_NC checks
This patch adds R_AARCH64_ADR_GOT_PAGE overflow and R_AARCH64_LD64_GOT_LO12_NC
unaligned value checks.

llvm-svn: 234746
2015-04-13 12:08:21 +00:00
Adhemerval Zanella 6f6472c41a ELF/Aarch64: Internal variable cleanup
This patch makes the AArch64GotAtomContent, AArch64Plt0AtomContent, and
AArch64PltAtomContent static and also cleanup their formatting.

llvm-svn: 234745
2015-04-13 11:44:44 +00:00
Adhemerval Zanella 9fc8102457 ELF/AArch64: Check linker created dynamic variables
Check the values of _GLOBAL_OFFSET_TABLE_ and _DYNAMIC variables created by
linker.  AArch64 version.

llvm-svn: 234744
2015-04-13 11:43:33 +00:00
Adhemerval Zanella c55179f847 ELF/AArch64: Check ADR_PREL_PG_HI21 for overflow
Add support for overflow checking when processing
R_AARCH64_ADR_PREL_PG_HI21 relocations and add test.

Patch Will Newton.

llvm-svn: 234743
2015-04-13 11:42:06 +00:00
Adhemerval Zanella 3274a849f4 ELF/AArch64: Add support for R_AARCH64_PREL16
Add support for the R_AARCH64_PREL16 relocation type and add tests.

Patch by Will Newton.

llvm-svn: 234742
2015-04-13 11:40:50 +00:00
Adhemerval Zanella 4def013264 ELF/AArch64: Add support for R_AARCH64_PREL64
Add support for the R_AARCH64_PREL64 relocation type and add tests.

Patch by Will Newton.

llvm-svn: 234741
2015-04-13 11:38:41 +00:00
Adhemerval Zanella a5752c73db ELF/AArch64: Add support for checking PREL32 for overflow
Add support for overflow checking when processing R_AARCH64_PREL32
relocations and add tests.

Patch by Will Newton.

llvm-svn: 234740
2015-04-13 11:36:51 +00:00
Adhemerval Zanella 4c9bad3549 ELF/AArch64: Add support for R_AARCH64_ABS16
Add support for the R_AARCH64_ABS16 relocation type and add tests.

Patch by Will Newton.

llvm-svn: 234739
2015-04-13 11:34:06 +00:00
Hans Wennborg 2a76f41511 Speculative build fix for lld on Windows
I can't access my Windows machine at the moment, but the build was breaking with:

c:\b\build\slave\crwinclanglld\build\src\third_party\llvm\tools\lld\lib\readerwriter\elf\mips\MipsTargetLayout.h(38) : error C2440: 'return' : cannot convert from 'lld:🧝:MipsGOTSection<ELFT> *' to 'lld:🧝:AtomSection<ELFT> *'
        with
        [
            ELFT=lld:🧝:Mips32ELType
        ]
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

I think this regressed caused in 234727: that the forward-declarations
of MipsGOTSection<> is not enough.

llvm-svn: 234736
2015-04-13 11:00:22 +00:00
Denis Protivensky f40ef51feb [ARM] Use std::call_once for thread safe initialization
Thanks to r234628 & r234631

llvm-svn: 234733
2015-04-13 10:18:21 +00:00
Denis Protivensky 8830b93fac [ARM] Replace branch to unreachable with assertion
llvm-svn: 234732
2015-04-13 08:47:38 +00:00
Simon Atanasyan da46480c4d [Mips] Explicitly instantiate MipsELFFile template class
Use explicit instantiation to reduce object files size.

llvm-svn: 234729
2015-04-13 08:35:04 +00:00
Simon Atanasyan aaf3df3a00 [Mips] Create MipsTargetHandler class object using factory functions
Right now MIPS instantiates MipsTargetHandler using Mips32ELType and
Mips64ELType. And in the future we can add a couple more types. That
leads to the large object file size because compiler has to create
copies of MipsTargetHandler and all realted classes for each types used
for instantiation.

The patch introduces two factory functions and puts each of them into
the separate cpp file. That allows to reduce size of single object file.

llvm-svn: 234728
2015-04-13 08:34:56 +00:00
Simon Atanasyan 4bc35460df [Mips] Move `MipsTargetLayout` class to the separate header
llvm-svn: 234727
2015-04-13 08:34:46 +00:00
Simon Atanasyan 88698b66c9 [Mips] Support R_MICROMIPS_GOT_HI/LO16 and R_MICROMIPS_CALL_HI/LO16 relocations
llvm-svn: 234726
2015-04-13 08:20:57 +00:00
Simon Atanasyan 62f261b014 [Mips] Support R_MIPS_CALL_HI16 / R_MIPS_CALL_LO16 relocations handling
llvm-svn: 234725
2015-04-13 08:20:48 +00:00
Simon Atanasyan 077372889b [Mips] Support R_MIPS_GOT_HI16 / R_MIPS_GOT_LO16 relocations handling
llvm-svn: 234724
2015-04-13 08:20:34 +00:00
Simon Atanasyan 4b115813d2 [Mips] Add more checkings to the test case
No functional changes.

llvm-svn: 234723
2015-04-13 08:20:26 +00:00
Nico Weber d9a21bf93a Revert r234649 "PECOFF: Use C++11 braced init list to make Version objects."
This doesn't compile with MSVC 2013:
include\lld/ReaderWriter/PECOFFLinkingContext.h(356) : error C2797:
    'lld::PECOFFLinkingContext::_imageVersion': list initialization
    inside member initializer list or non-static data member initializer
    is not implemented
include\lld/ReaderWriter/PECOFFLinkingContext.h(357) : error C2797:
    'lld::PECOFFLinkingContext::_imageVersion': list initialization
    inside member initializer list or non-static data member initializer
    is not implemented

llvm-svn: 234676
2015-04-11 01:32:52 +00:00
Rui Ueyama 942d51a25f Replace a macro with an inline function.
llvm-svn: 234650
2015-04-10 22:05:11 +00:00
Rui Ueyama 4d57247236 PECOFF: Use C++11 braced init list to make Version objects.
llvm-svn: 234649
2015-04-10 21:57:06 +00:00
Rui Ueyama 4a576bfd23 Use C++11 non-static member initialization.
llvm-svn: 234648
2015-04-10 21:49:28 +00:00
Rui Ueyama 8330835197 Attempt to fix buildbots.
lldNative was removed in r234641.

llvm-svn: 234646
2015-04-10 21:42:16 +00:00
Rui Ueyama aabd7ca452 Do s/_context/_ctx/g globally.
I believe this patch eliminates all remaining uses of _context
or _linkingContext variable names. Consistent naming improves
readability.

llvm-svn: 234645
2015-04-10 21:40:59 +00:00
Rui Ueyama 08d9520f89 Fix docs-lld-html build.
llvm-svn: 234644
2015-04-10 21:37:42 +00:00
Rui Ueyama aa7b304ea7 Remove the Native file format.
The Native file format was designed to be the fastest on-memory or
on-disk file format for object files. The problem is that no one
is working on that. No LLVM tools can produce object files in
the Native, thus the feature of supporting the format is useless
in the linker.

This patch removes the Native file support. We can add it back
if we really want it in future.

llvm-svn: 234641
2015-04-10 21:23:51 +00:00
Simon Atanasyan 1c1b4366af [Mips] Fix broken test case
llvm-svn: 234639
2015-04-10 21:19:01 +00:00
Rui Ueyama 74c629be81 ELF: Simplify assignments to "result"
This file is not -Wconversion-clean, and seems like we don't care
about that except these lines. Fix these lines for simplicity.

llvm-svn: 234637
2015-04-10 21:03:20 +00:00
Simon Atanasyan 720f52a961 [Mips] Add -pcrel-eh-reloc command line option
This MIPS specific option controls R_MIPS_EH relocation handling.
If -pcrel-eh-reloc is specified R_MIPS_EH relocation should be handled
like R_MIPS_PC32 relocation.

llvm-svn: 234635
2015-04-10 21:00:41 +00:00
Simon Atanasyan 54b1d56c01 [Mips] Support R_MIPS_EH relocation handling
The patch supports just the R_MIPS_EH relocation handling and does not
implement full specification of compact exception tables for MIPS ABIs.

llvm-svn: 234634
2015-04-10 21:00:29 +00:00
Simon Atanasyan ada248cd1c [Mips] Replace MipsTargetHandler member function getGP() by getGPAddr()
When we call getGP() we need in fact _gp symbol address. Let's cache its
value and return it directly from the new getGPAddr() function.

llvm-svn: 234632
2015-04-10 20:55:10 +00:00
Simon Atanasyan 1f50cb1d13 [Mips] Use std::call_once for thread safe initialization
The commit is inspired by r234628. Thanks Rui for the idea.

llvm-svn: 234631
2015-04-10 20:55:04 +00:00
Simon Atanasyan 2bafa8342c [Mips] Fix typo in the comment
llvm-svn: 234630
2015-04-10 20:54:58 +00:00
Rui Ueyama ee0c60679a Fix minor threading issue.
Because calls of applyRelocation is parallelized, all functions
called from that need to be thread-safe. This piece of code
didn't use any synchronization mechanism, so it was not safe.

llvm-svn: 234628
2015-04-10 19:55:35 +00:00
Denis Protivensky fb8afb8f81 [ARM] Implement PLT for dynamic pass
This includes implementation of PLT0 entry.

For testing, libfn.so binary is added since
there's no way to link shared objects with lld yet.

llvm-svn: 234588
2015-04-10 11:41:27 +00:00
Denis Protivensky e9c336aeb5 [ARM] Rework GOT/PLT entry generation
Use consistent naming: commonly used generator methods
don't have 'Entry' suffices.

llvm-svn: 234585
2015-04-10 11:05:11 +00:00
Denis Protivensky 8ad3627e19 [ARM] Replace dyn_cast with isa check
llvm-svn: 234582
2015-04-10 10:30:04 +00:00
Denis Protivensky b56dff5729 [ARM] Improve veneer handling and introduce handlePlain method
Handle veneers only for call-like relocations.

llvm-svn: 234580
2015-04-10 09:54:10 +00:00
Denis Protivensky 4dae7b02be [ARM] Remove unused variable in dynamic pass
llvm-svn: 234576
2015-04-10 07:53:18 +00:00
Denis Protivensky 7fc8aa9f1c [ARM] Add skeleton for dynamic relocation pass
llvm-svn: 234573
2015-04-10 07:42:08 +00:00
Rui Ueyama 17a2fa1e32 Remove redundant parentheses.
llvm-svn: 234558
2015-04-10 02:18:23 +00:00
Rui Ueyama 27bfbed359 Do not use default arguments for trivial functions.
llvm-svn: 234557
2015-04-10 02:15:13 +00:00
Rui Ueyama 709a0ecc87 Remove unused return values.
llvm-svn: 234556
2015-04-10 02:06:28 +00:00
Davide Italiano b63c9c32dc Reapply r234378, with test fixed (by emaste).
Hopefully this time the build won't be broken.

llvm-svn: 234553
2015-04-10 01:40:25 +00:00
Rui Ueyama ab5d90568e ELF: Don't use APPLY_RELOC macro.
In other ELF ports, we don't use the macro. This patch removes the
macro for consistency and readability.

llvm-svn: 234552
2015-04-10 00:19:41 +00:00
Rui Ueyama 84f93415f4 ELF: Move Hexagon linker helper function to Hexagon directory.
Because no one except Hexagon uses the header, we don't need to maintain
the header in the common directory. Also de-template the function for
readability.

llvm-svn: 234551
2015-04-10 00:11:54 +00:00
Rui Ueyama 6d1a121b55 Remove dead code.
llvm-svn: 234548
2015-04-10 00:04:44 +00:00
Rui Ueyama 0a997cbd3f Fix undefined behavior.
Having std:move(mb) and mb->getBuffer() in the same argument list is not safe
because the order of evaluation is not defined.

llvm-svn: 234541
2015-04-09 22:04:45 +00:00
Rui Ueyama 2e8cb722de ELF: Move CreateELF() from its own file to ELFReader.h.
CreateELF.h was included only by ELFReader.h, and it was used only
by ELFReader class. By making the function a member of the class,
we can remove template parameters.

llvm-svn: 234540
2015-04-09 21:55:47 +00:00
Rui Ueyama adafac6549 Update design.rst to remove a mention about round-trip tests.
llvm-svn: 234534
2015-04-09 20:43:38 +00:00
Denis Protivensky 455e44b0e4 [ARM] clang-format ARM sources
llvm-svn: 234474
2015-04-09 10:17:22 +00:00
Denis Protivensky 6b3a33ff00 [ARM] Add mapping symbols to veneers
This required splitting up veneer atoms into pieces,
where every piece is paired with mapping atom of
the corresponding type.

llvm-svn: 234473
2015-04-09 09:59:18 +00:00
Rui Ueyama 2effbd6b68 AtomVector: Reorder member orders to use template alias in AtomRange.
llvm-svn: 234453
2015-04-08 23:12:48 +00:00
Rui Ueyama de40bd4cf9 Rename atom_collection -> AtomVector.
Type names should start with an uppercase letter in the LLVM coding style.

llvm-svn: 234452
2015-04-08 23:05:59 +00:00
Rui Ueyama b0db07bf90 Separate atom_collection type into two different types. NFC.
atom_collection is basically a wrapper for std::vector. The class
provides begin and end member functions, so that it "hides" the
other member functions provided by std::vector. However, you can
still directly access _atoms member since the member is not
protected.

We cannot simply make the member private because we need that member
when we are constructing atom vectors.

This patch splits atom_collection into two types: std::vector<Atom *>
and AtomRange. When we are constructing atom vectors, we use the
former class. We return instances of the latter class from File
objects so that callers cannot add or remove atoms from the lists.

std::vector<Atom *> is automatically converted to AtomRange.

llvm-svn: 234450
2015-04-08 23:02:11 +00:00
Rui Ueyama 42a3dfb22c Add begin() and end() to atom_collection that returns non-const iterators.
llvm-svn: 234445
2015-04-08 21:59:08 +00:00
Rui Ueyama ae0299f040 Replace atom_iterator with a template alias.
llvm-svn: 234444
2015-04-08 21:59:06 +00:00
Rui Ueyama 1a6ec93616 Merge atom_collection_vector with atom_collection.
atom_collection_vector is the only derived class of atom_collection.
This patch merges the two.

llvm-svn: 234443
2015-04-08 21:59:04 +00:00
Rui Ueyama 2f05640409 Remove atom_collection_empty class.
llvm-svn: 234442
2015-04-08 21:59:00 +00:00
Rui Ueyama 5d6ff3d2ee vec.data() and vec.data() + vec.size() are both safe even if the vector is empty.
llvm-svn: 234436
2015-04-08 21:13:23 +00:00
Rui Ueyama 1e67707a66 YAML: Remove blank class using alias template.
llvm-svn: 234435
2015-04-08 21:05:45 +00:00
Rui Ueyama df666170ae Native: Remove AtomArray and use atom_collection_vector instead.
llvm-svn: 234434
2015-04-08 21:00:33 +00:00
Rui Ueyama d3165af756 Native: Use tempalte to remove duplicate code. NFC.
llvm-svn: 234432
2015-04-08 20:40:46 +00:00
Rui Ueyama 0d69284bec Native: Simplify expressions. NFC.
llvm-svn: 234431
2015-04-08 20:40:45 +00:00
David Blaikie 71df405895 Remove redundant virtual on member functions marked 'override'.
llvm-svn: 234419
2015-04-08 17:08:27 +00:00
Rui Ueyama 9842a965f6 Remove unused typedefs.
llvm-svn: 234415
2015-04-08 16:59:03 +00:00
Rui Ueyama e3efa415de Revert "Allow undefined symbols in shared library by default."
This reverts commit r234378 because it broke buildbots.

llvm-svn: 234414
2015-04-08 16:55:03 +00:00
Simon Atanasyan d42488a637 [ELF] Remove redundant GOTFile classes
llvm-svn: 234397
2015-04-08 10:06:28 +00:00
Simon Atanasyan 8e951ce392 [ELF] Do not save a reference to GOTFile instance in xxxWriter classes
It's a follow-up to r234347. We do not need to keep a reference to
`GOTFile` instance in a xxxWriter class after ownership is transferred
to the caller of the `createImplicitFiles` method.

llvm-svn: 234396
2015-04-08 09:19:45 +00:00
Davide Italiano 0e6a264673 Allow undefined symbols in shared library by default.
It's not our business to resolve those undefined symbols.
We just trust the linker will load the library and its dependencies
correctly, which is actually what happens, modulo bugs in the dynamic
linker itself.

PR:		23035
Differential Revision:	http://reviews.llvm.org/D8886

llvm-svn: 234378
2015-04-08 01:00:19 +00:00
Rui Ueyama 9a736cf29f ELF: Minor simplification.
MergeSectionKey is a tiny struct. We don't need a constructor for that.
The good old way to initialize a struct works fine.

llvm-svn: 234371
2015-04-07 22:46:01 +00:00
Rui Ueyama 3b9a91a18d MachO: Remove unused vectors from MachHeaderAliasFile. NFC.
llvm-svn: 234369
2015-04-07 22:35:29 +00:00
Rui Ueyama 142877f450 Remove unused vectors from FileArchive.
Archive files don't have any symbols (their members do).
The vectors deleted here were always empty.

llvm-svn: 234368
2015-04-07 22:32:19 +00:00
Rui Ueyama 5a79fbeb2e ELF: Simplify ELFFile by deriving from SimpleFile instead of File.
SimpleFile defines defined(). undefined(), sharedLibrary() and absolute().
We should use the class instead of deriving from the base class and
re-defining the member functions in ELFFile.

llvm-svn: 234367
2015-04-07 22:27:43 +00:00
Rui Ueyama 18cd75cc47 Define SimpleFile::addAtom for concrete atom types.
Previously, addAtom always used dynamic dispatching mechanism to
bin atoms. This patch eliminates dynamic dispatching in most cases.

llvm-svn: 234365
2015-04-07 22:21:18 +00:00
Simon Atanasyan 64bcb690e9 [ELF] Set `addAbsoluteAtom` and `addUndefinedAtom` functions return type to void
We do not use values returned by these functions anywhere.
So let's return nothing.

llvm-svn: 234358
2015-04-07 21:12:28 +00:00
Simon Atanasyan 3dba8a2d96 [ELF] Remove unused xxxWriter class fields
llvm-svn: 234357
2015-04-07 21:12:18 +00:00
Simon Atanasyan 073e9fb5e1 [ELF] Remove redundant override methods which just call base class functions
llvm-svn: 234356
2015-04-07 21:12:02 +00:00
Rui Ueyama 3c45cffd68 Merge MutableFile with SimpleFile.
SimpleFile is the only derived class of MutableFile.
This patch reduces the height of class hierarchy by removing
MutableFile class.

llvm-svn: 234354
2015-04-07 20:43:38 +00:00
Simon Atanasyan 64e36b67e2 [ELF] Simplify adding default atoms
Now 'writer' creates an instance of `RuntimeFile` in the constructor, then
populates the file in the virtual function `addDefaultAtoms`, then pass
owning of this file to the caller of virtual function `createImplicitFiles`.

First, we do not need to keep an instance of `RuntimeFile` so long. It is
enough to create the file, right after that populate it and pass the owning.

Second, relationship between `createImplicitFiles` and `addDefaultAtoms`
is complicated. The `createImplicitFiles` might call `addDefaultAtoms`,
overridden version of `addDefaultAtoms` might call base class `addDefaultAtoms`,
and overridden version of `createImplicitFiles` might call base class
`createImplicitFiles` as well as `addDefaultAtoms`.

The patch solves both problems above. It creates and populates runtime files
right in the createImplicitFiles(), removes `addDefaultAtoms` at all and
does not keep references to runtime files in class fields.

llvm-svn: 234347
2015-04-07 20:11:38 +00:00
Denis Protivensky 14ed198ff7 [ARM] Use getMappingAtomName in Release only
llvm-svn: 234311
2015-04-07 11:51:39 +00:00
Denis Protivensky dd7adf7a18 [ARM] Rename applyThmReloc => applyThumb32Reloc
llvm-svn: 234302
2015-04-07 07:14:13 +00:00
Denis Protivensky 6c50e88c0d [ARM] Add mapping symbols to PLT entries
Make PLT entry atoms represent mapping symbols in the Release mode,
while in the Debug mode they are still function-like symbols
with regular names.
It's legal that mapping symbols denote unnamed parts of code,
and PLT entries are not required to have function-like names.

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

llvm-svn: 234301
2015-04-07 07:04:42 +00:00
Simon Atanasyan d526486763 [ELF] Remove redundant const_cast
No functional changes.

llvm-svn: 234293
2015-04-07 04:38:30 +00:00
Rui Ueyama 752a8c3e55 ELF: Minimum alignment value is 1, not 0. NFC.
Maybe we can interpret alignment 0 as "don't care", but for
consistency, it's good to set 1 instead of 0 where we allow
any alignments.

llvm-svn: 234284
2015-04-07 03:44:26 +00:00
Rui Ueyama 0e46755821 ELF: Add a comment to ELFFile::findAtom.
Also changed the local variable names to avoid line wrapping.

llvm-svn: 234281
2015-04-07 02:52:34 +00:00
Rui Ueyama 11dcc79de1 Fix weird comment line-wrapping.
llvm-svn: 234279
2015-04-07 02:26:42 +00:00
Rui Ueyama f11343e68e Use early continue.
llvm-svn: 234278
2015-04-07 02:20:33 +00:00
Rui Ueyama add2a66c00 ELF: Move more code from createAtoms to handleGnuLinkOnceSection.
So that createAtoms become more readable.

llvm-svn: 234277
2015-04-07 02:11:56 +00:00
Rui Ueyama f122b91a02 ELF: Simplfiy ELFFile::createAtom.
createAtom function did too much in a single for-loop. This patch
splits the for-loop and extract COMDAT handling into a separate
function.

llvm-svn: 234276
2015-04-07 01:56:07 +00:00
Rui Ueyama c9f801504a ELF: Do not return error from handle{CommonSymbol,MergeString}.
llvm-svn: 234273
2015-04-07 01:14:24 +00:00
Rui Ueyama 29e56d06f2 ELF: Do not return error from handleAbsoluteSymbol.
This function never fails.

llvm-svn: 234272
2015-04-07 01:08:16 +00:00
Rui Ueyama 00ecdb53d0 ELF: Do not return error from handleUndefinedSymbol.
This function is not supposed to return an error value.

llvm-svn: 234271
2015-04-07 01:04:15 +00:00
Rui Ueyama 9918155779 ELF: Do not return error from handleDefinedSymbol.
handleDefinedSymbol has return type of ErrorOr<ELFDefinedAtom *>.
However, it never returns an error. We are not checking errors.
It's marked as ErrorOr "just in case". That's a bad engineering
practice.

This patch simplifies the return type of the function.

llvm-svn: 234269
2015-04-07 01:00:20 +00:00
Rui Ueyama 7c869e4821 ELF: Simplify CreateELF.
CreateELF was a combination of templates and C preprocessor macros.
This patch removes uses of macros.

http://reviews.llvm.org/D8810

llvm-svn: 234253
2015-04-06 23:02:47 +00:00
Davide Italiano 8b4956a507 Fix a very silly typo in my previous commit. I need more coffee.
Spotted by Simon Atanasyan.

llvm-svn: 234252
2015-04-06 22:57:58 +00:00
Davide Italiano 553e118147 [GNU] Implement --enable-new-dtags/--disable-new-dtags
PR:		23036
Differential Revision:	http://reviews.llvm.org/D8836

llvm-svn: 234240
2015-04-06 21:45:31 +00:00
Rui Ueyama 0ac129903a ELF: Do not mix link-once and group sections.
Previously, we put both link-once and group sections into the same map
and seaparated them out when we use them. Apparently we should put them
into seaprate maps in the first place.

This piece of code is added recently, and I still don't understand all
of them. Looks like we need to clean this up even more.

llvm-svn: 234223
2015-04-06 21:21:43 +00:00
Simon Atanasyan c437888f5a Replace the `createImplicitFiles` method return type with `void`
All instances of the `createImplicitFiles` always return `true` and this
return value is used nowhere.

llvm-svn: 234205
2015-04-06 20:43:35 +00:00
Rui Ueyama 230d2ec75f Remove return after report_fatal_error which has noreturn attribute.
llvm-svn: 234204
2015-04-06 20:25:18 +00:00
Rui Ueyama 02b5a800c5 Fix weird line-wrapping.
llvm-svn: 234203
2015-04-06 20:10:09 +00:00
Rui Ueyama 0fbf5aa205 Use llvm::cast at where we don't expect a null value.
llvm-svn: 234199
2015-04-06 19:45:32 +00:00