Commit Graph

2815 Commits

Author SHA1 Message Date
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
Denis Protivensky 0575c5de68 [ARM] Implement R_ARM_TLS_IE32 for dynamic executable
llvm-svn: 235182
2015-04-17 11:30:29 +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
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
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
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 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
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 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 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
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 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
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 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 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 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 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
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 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
Simon Atanasyan fa58038914 [Mips] Guard modification of register usage masks by mutex
llvm-svn: 234167
2015-04-06 16:07:19 +00:00
Simon Atanasyan 596dae5fc2 [LinkerScript] Handle symbols defined in linker scripts in case of shared lib
This patch is a follow-up to the rL232409 and allows define symbols
in a linker script in case of linking shared library.

llvm-svn: 234163
2015-04-06 15:15:01 +00:00
Simon Atanasyan a19820ddb4 [ELF] Use override keyword instead of virtual
No functional changes.

llvm-svn: 234162
2015-04-06 15:09:39 +00:00
Simon Atanasyan ac17bfd699 [ELF] Use override keyword instead of virtual
No functional changes.

llvm-svn: 234157
2015-04-06 13:26:15 +00:00
Simon Atanasyan 3dac3ba595 [ELF] Remove redundant forward class declarations
No functional changes.

llvm-svn: 234156
2015-04-06 13:26:10 +00:00
Simon Atanasyan cd9f268b50 [Mips] Remove redundant non-template MipsRelocationHandler class
llvm-svn: 234155
2015-04-06 13:26:04 +00:00
Simon Atanasyan 58a7fd48dc [Mips] Replace MipsRelocationHandler::readAddend() by a regular function
The readAddend() does not depend on MipsRelocationHandler and should not
be its member function.

llvm-svn: 234154
2015-04-06 13:25:58 +00:00
Simon Atanasyan 3a8691a27a [Mips] Reformat the code with clang-format
llvm-svn: 234153
2015-04-06 13:25:52 +00:00
Denis Protivensky 2000211ff3 [AArch64] Fix error in AARCH64_ADR_GOT_PAGE handler
The error was introduced during mechanical replacement
of raw memory reads/writes to use readxxle/writexxle functions
in r230725.

Noted and fixed by Suprateeka R Hegde <hegdesmailbox@gmail.com>

llvm-svn: 234144
2015-04-06 07:44:59 +00:00
Davide Italiano fd52bbcf58 Strip .strtab and .symtab when --strip-all is used.
This matches other linkers behaviour. Moreover, there's really
no need to keep them around.

Reported by: Rafael Avila de Espindola

PR:		22890
llvm-svn: 234130
2015-04-05 22:47:54 +00:00
Benjamin Kramer 02613337e3 [elf] Fix a silly memory leak. std::string has a non-trivial dtor.
llvm-svn: 234120
2015-04-05 15:53:20 +00:00
Simon Atanasyan efc006b573 [Mips] Rename MipsLinkingContext class method
getMergeReginfoMask => getMergedReginfoMask

llvm-svn: 234116
2015-04-05 09:01:53 +00:00
Simon Atanasyan 4c5b23f6df [Mips] Support writing .MIPS.options section into the linked file
In case of MIPS N64 ABI linker should merge registers usage masks stored
in the input .MIPS.options sections and save result into the output
.MIPS.options section.

llvm-svn: 234115
2015-04-05 09:01:46 +00:00
Simon Atanasyan 3ceaceb26a [Mips] Do not use array initializer to fix Windows build bots
llvm-svn: 234105
2015-04-04 19:48:29 +00:00
Simon Atanasyan c3899d2234 [Mips] Support writing .reginfo section into the linked file
In case of MIPS O32 ABI linker should merge registers usage masks stored
in the input .reginfo sections and save result into the output .reginfo
section.

The ABI states that the .reginfo section should be put into the separate
segment. This requirement is not implemented in this patch.

llvm-svn: 234103
2015-04-04 19:13:32 +00:00
Simon Atanasyan 1d359d3b5b [Hexagon] Remove duplicated typedef
The `HexagonELFType` is declared in the HexagonLinkingContext.h.

llvm-svn: 234089
2015-04-04 05:19:58 +00:00
Simon Atanasyan 1649aea9c6 [Hexagon][Mips] Rename template arguments <arch>ELFType to ELFT
In all other ELF related classes we use `ELFT` abbreviation.

llvm-svn: 234088
2015-04-04 05:19:51 +00:00
Rui Ueyama a5f1ae1ad0 ELF: Use short variable names in <Arch>RelocationHandlers.cpp.
Functions in the files are hard to read because of line wrapping.
Use shorter names for local variables so that the lines fit
within 80 columns.

llvm-svn: 234087
2015-04-04 04:22:27 +00:00
Rui Ueyama b2e6190aca Remove redundant anonymous namespace.
llvm-svn: 234085
2015-04-04 04:10:08 +00:00
Rui Ueyama 09f8b75b52 ELF: Merge ELFTargets.h with ELFLinkingContext.h.
These functions are "constructors" of the LinkingContexts. We already
have auxiliary classes and functions for ELFLinkingContext in the header.
They fall in the same category.

llvm-svn: 234082
2015-04-04 03:24:42 +00:00
Rui Ueyama 59b0bfef0d ELF: Return TargetRelocationHandler instead of <ArcH>TargetRelocationHandler.
getRelocationHandler is a public interface to get an instance of
TargetRelocationHandler. We don't use any member function other than
applyRelocations to a returned instance. Returning a base class instance
suffices here. (If a return type is a derived class, it looks like we were
using derived classes features.)

llvm-svn: 234081
2015-04-04 02:59:52 +00:00
Rui Ueyama 55f5b2b277 Remove a parameter for file extension from canParse.
canParse took three parameters -- file magic, filename extension and
memory buffer. All but YAMLReader ignored the second parameter.
This patch removes the parameter.

llvm-svn: 234080
2015-04-04 02:44:36 +00:00
Rui Ueyama 103cb33d08 ELF: Make private members private.
llvm-svn: 234077
2015-04-04 02:26:17 +00:00
Rui Ueyama aa1eb0c2a5 ELF: Remove ELF{Object,DSO}Reader alias templates.
Because of the previous change (r234074), ELFObjectReader became just
an alias for ELFReader. We can replace all occurrences of ELFObjectReader
with ELFReader.

In this patch, I also replaced ELFDSOReader to remove the alias template.

llvm-svn: 234076
2015-04-04 02:16:26 +00:00
Rui Ueyama db9e9d83b6 ELF: Teach File classes about their file magics.
So that we can remove one template parameter from ELFReader.
ELF port is heavily templatized, and I want to reduce the usage
where possible.

llvm-svn: 234074
2015-04-04 02:07:30 +00:00
Rui Ueyama 22f0b3f1a5 s/context/ctx/g on lib/Driver/Driver.cpp.
llvm-svn: 234073
2015-04-04 01:37:25 +00:00
Rui Ueyama c6fcfd4178 Remove unused member function declarations.
llvm-svn: 234072
2015-04-04 01:37:23 +00:00
Rui Ueyama 21d22ca11a Remove unused includes and forward declarations.
llvm-svn: 234070
2015-04-04 00:25:22 +00:00
Rui Ueyama 4d200e3859 Remove unused functions.
llvm-svn: 234069
2015-04-04 00:12:27 +00:00
Rui Ueyama 133933bb42 ELF: Define mergeHeaderFlags to ELFLinkingContext.
Only MIPS defined the member function, but this feature is not actually
MIPS-specific. Also, the dependency to the MIPS-only member function
prevented us from merging <Arch>ELF{Object,DSO}Reader classes.

This patch moves the feature from MipsLinkingContext to LinkingContext.

llvm-svn: 234068
2015-04-04 00:10:14 +00:00
Simon Atanasyan a2404f898a [ELF] Remove unused typedef
llvm-svn: 234066
2015-04-03 23:07:18 +00:00
Simon Atanasyan c36c80c2f2 [ELF] Merge Layout and TargetLayout class
It is enough to have single TargetLayout class.

llvm-svn: 234065
2015-04-03 23:07:13 +00:00
Rui Ueyama 25a0d3dd64 ELF: Merge ELF{Object,DSO}Reader implementations.
The two classes are the same other than a few exceptions.
This patch merges them using templates.

llvm-svn: 234060
2015-04-03 22:12:18 +00:00
Rui Ueyama fdcfe466e3 ELF: Remove <Arch>ELFReader.h. NFC.
<Arch>ELFReader.h contains only a few typedefs. The typedefs are used
only by one class in <Arch>TargetHandler.h. Thus, the headers don't
worth to be independent files.

Since MipsELFReader.h contains code other than the boilerplate, I didn't
touch that file in this patch.

llvm-svn: 234056
2015-04-03 21:22:20 +00:00
Simon Atanasyan 2181c10b5b [ELF] Delete empty TargetLayout class and rename DefaultLayout to TargetLayout
No functional changes.

llvm-svn: 234052
2015-04-03 21:01:07 +00:00
Rui Ueyama 3fbed259b6 ELF: Fix header file dependencies.
<Arch>TargetHandler.h and <ArcH>RelocationHandler.h include each other.
This patch breaks the circular dependencies.

llvm-svn: 234050
2015-04-03 20:56:22 +00:00
Rui Ueyama 72553767d5 ELF: Pass file types instead of type traits to ELFObjectReader.
All <Arch>ELFFileCreateFileTraits structs are the same except its file type.
That means that we don't need to pass the type traits. Instead, we can only
pass file types. By doing this, we can remove copy-pasted boilerplates.

llvm-svn: 234047
2015-04-03 20:29:37 +00:00
Rui Ueyama 077b2bf0c9 Inline typedef'ed type that's used only once. NFC.
result_type is no longer part of the type traits, so keeping it here
is confusing.

llvm-svn: 234044
2015-04-03 19:46:56 +00:00
Simon Atanasyan 400c9852cb [ELF] Fix Layout class name in the comment
No functional changes.

llvm-svn: 234040
2015-04-03 19:35:12 +00:00
Rui Ueyama bba452f23e ELF: Remove partial class definitions of <Arch>LinkingContexts.
What we are doing in ELFTarget.h was dubious. In the file, we define
partial classes of <Arch>LinkingContexts to declare only static member
functions. We have different (complete) class definitions in other files.
They would conflict if they exist in the same compilation unit (because
the ones defined in ELFTarget.h has only static member functions).
I don't think this was valid C++.

http://reviews.llvm.org/D8797

llvm-svn: 234039
2015-04-03 19:32:31 +00:00
Leny Kholodov a0ccf1abb7 Fix for revision r234009 (gcc/msvc compilation differences)
llvm-svn: 234014
2015-04-03 14:44:33 +00:00
Leny Kholodov 95ed78b85a [ARM] Implementation of R_ARM_TARGET1 relocation
This patch provides implementation of R_ARM_TARGET1 relocation with
configuration of its behaviour from a command line. This patch provides
two command line options for GnuLd driver: --arm-target1-rel and
--arm-target1-abs (similar to ld option names with extra prefix 'arm-').
So user may choose which behaviour of R_ARM_TARGET1 is preferred for his
implementation of libc.

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

llvm-svn: 234009
2015-04-03 12:03:47 +00:00
Rui Ueyama 69af2e717e ELF: Remove <Arch>ELFFileCreateELFTraits::result_type.
result_type is always ErrorOr<unique_ptr<File>>, and since the type traits
is for instantiating ELF files, it's unlikely that we want to return
something else. This patch removes that type.

llvm-svn: 233948
2015-04-02 21:14:33 +00:00
Simon Atanasyan 8189ee9a1e [Mips] Inline the MipsELFWriter::hasGlobalGOTEntry function
No functional changes.

llvm-svn: 233924
2015-04-02 16:44:26 +00:00
Rui Ueyama b709f8b6ef ELF: Always use variadic templates in CreateELF.h.
Since we no longer support MSVC 2012, we can assume that variadic
templates are always supported. This patch removes an #ifdef for
C++ compilers that don't support variadic templates.

llvm-svn: 233901
2015-04-02 07:28:19 +00:00
Denis Protivensky 2fc953bb98 [ARM] Generate PLT entries for calls from ARM and Thumb code
The function call that goes through PLT table may be performed
from both ARM and Thumb code.
This situation requires adding a veneer to original PLT code
(which is always ARM) to effect Thumb-to-ARM transition.

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

llvm-svn: 233900
2015-04-02 07:23:11 +00:00
Denis Protivensky ff51abcc52 [ARM] Report fatal error for wrong ARM entry point
The case is possible with wrong input, so report
an error instead of using llvm_unreachable.

llvm-svn: 233899
2015-04-02 07:03:44 +00:00
Rui Ueyama 0ee57cede0 ELF: Remove {AArch64,X86,X86_64}ELFFile because they are empty.
llvm-svn: 233897
2015-04-02 06:50:29 +00:00
Rui Ueyama 0a1fbb7b0c ELF: Replace empty classes with typedefs.
llvm-svn: 233896
2015-04-02 06:00:42 +00:00
Rui Ueyama b965ac5dc9 ELF: Remove a template parameter from ELF{Object,DOS}Reader constructors.
There is one-to-one correspondence between ELF machine type and a
LinkingContext. We passed them as separate arguments to the constructor.
This patch is to teach the LinkingContexts about their machine types,
so that we don't need to pass that data as separate arguments.

llvm-svn: 233894
2015-04-02 05:19:36 +00:00
Rui Ueyama 4229b946a8 ELF: Mips: Remove unused field and almost-empty class.
Looks like MipsTargetHandler::_runtimeFile is unused.
MipsRuntimeFile doesn't seem to add values to the base class,
so I removed that class too.

llvm-svn: 233888
2015-04-02 04:48:30 +00:00
Rui Ueyama 7d5492d9ab ELF: Move registerRelocationNames() from TargetHandler to <Arch>ELFLinkingContext.
registerRelocationNames() function is called to register all known
ELF relocation types to the central registry. Since we have separate
LinkingContext class for each ELF machine type, we need to call the
function for each LinkingContext.

However, the function belonged to TargetHandler instead of LinkingContext.
So we needed to do ctx.getTargetHandler().registerRelocationNames().
This patch removes that redundant getTargetHandler call by moving the
function from TargetHandler to LinkingContext.

Conceptually this patch is small, but in reality it's not that small.
It's because the same code is copied to each architecture.
Most of this patch is just repetition. We need to merge them, but
that cannot be done in this patch.

llvm-svn: 233883
2015-04-02 04:18:54 +00:00
Rui Ueyama 0052736eb1 ELF: Move x86-64-only function from DefaultLayout to X86_64TargetLayout.
Also removed some over-generalization added in r232866, such as
making a function take two parameters and pass two equivalent
arguments to the function.

llvm-svn: 233882
2015-04-02 01:36:02 +00:00
Rui Ueyama a9b549f924 ELF: Remove empty classes.
llvm-svn: 233880
2015-04-02 01:22:23 +00:00
Rui Ueyama 8ecb0b68c1 ELF: Make createWriterELF's type consistent with other functions.
Other createWriter<Arch> functions take <Arch>LinkingContext as arguments.
Only createWriterELF was an exception. This patch makes it consistent with
others.

llvm-svn: 233878
2015-04-02 01:02:58 +00:00
Rui Ueyama 943206da8e ELF: x86, x86-64, ARM, AArch64: Remove architecture name prefixes from class members.
llvm-svn: 233873
2015-04-02 00:19:04 +00:00
Rui Ueyama 4e725665b0 Remove unused varaible.
llvm-svn: 233872
2015-04-02 00:18:58 +00:00
Rui Ueyama 4507003622 ELF: Remove <Arch>TargetHandler::kindString.
<Arch>TargetHandler::kindString is a static member variable
containg a list of names of relocation types.

The member is used only by one function, registerRelocationNames,
so they don't have to be a static member.

This patch makes the visibility of the data narrower by making
them file-scoped variables in small files.

llvm-svn: 233867
2015-04-01 23:55:10 +00:00
Rui Ueyama cb15900a7f Remove unused variable.
llvm-svn: 233864
2015-04-01 22:55:16 +00:00
Rui Ueyama 5c9709f956 Use llvm::make_unique.
llvm-svn: 233863
2015-04-01 22:51:46 +00:00
Rui Ueyama 0d83d61297 Use C++ non-static member initialization.
llvm-svn: 233859
2015-04-01 22:28:00 +00:00
Simon Atanasyan 2948dfe89f [Mips] Remove 'mips' prefix from class member fields names
No functional changes.

llvm-svn: 233812
2015-04-01 15:30:53 +00:00
Denis Protivensky 5466b1c0d2 [ARM] Set specific flags in ELF header
llvm-svn: 233799
2015-04-01 11:39:53 +00:00
Denis Protivensky b538262646 [ARM] Enhance checks for entry point
llvm-svn: 233798
2015-04-01 11:36:58 +00:00
Shankar Easwaran 83aa6d02d8 [ELF][Hexagon] Add comments related to hexagon relocations.
No functional changes.

llvm-svn: 233783
2015-04-01 03:07:01 +00:00
Shankar Easwaran ee39d33175 [Gnu] Support an other form of defsym option
llvm-svn: 233782
2015-04-01 03:06:59 +00:00
Rui Ueyama c8dad8e324 ELF: Remove TargetHandlerBase by merging it with TargetHandler.
In r233772, I removed an empty class, DefaultTargetHandler, from
the class hierarchy by merging the class with TargetHandler. I then
found that TargetHandler and its base class, TargetHandlerBase,
are also almost the same.

We need to go deeper.

In this patch, I merged TargetHandlerBase with TargetHandler.
The only difference between them is the existence (or absense)
of a pure virtual function registerRelocationName(). I added that
function to the (new) TargetHandler.

One more thing is that TargetHandler was templated for no reason.
I made it non-templated class.

llvm-svn: 233773
2015-04-01 00:00:36 +00:00
Rui Ueyama c2cf52ae24 ELF: Remove dead class that does nothing in class hierarchy.
DefaultTargetHandler is the base class of all <Arch>TargetHandler classes,
and it's the only derived class of TargetHandler class.

TargetHandler and DefaultTargetHandler are actually the same. They define
the same set of pure virtual functions. DefaultTargetHandler is a useless
class in the class hierarchy -- it shouldn't have been added in the first place.

This patch makes all <Arch>TargetHandler classes directly derive from
TargetHandler and removes DefaultTargetHandler.

llvm-svn: 233772
2015-03-31 23:01:19 +00:00
Rui Ueyama 5d2939302a ELF: Make findAbsoluteAtom return AtomLayout* instead of an iterator.
All calls of findAbsoluteAtoms seem a bit awkward because of the type
of the function. It semantically returns a pointer to an AtomLayout or
nothing, so I made the function return AtomLayout*.

In this patch, I also expanded some "auto"s because their actual type
were not obvious in their contexts.

llvm-svn: 233769
2015-03-31 22:37:59 +00:00
Rui Ueyama 6a75d842c9 ELF: Fix dereferencing end() iterator.
findAbsoluteAtom() returns absoluteAtom().end() if no atom is found.
Dereferencing end() value results an undefined behavior.

llvm-svn: 233765
2015-03-31 22:08:43 +00:00
Rui Ueyama 1490b3512e ELF: Remove TargetHandler::getTargetLayout.
Only MIPS used that member function, and by removing the use of the
function, I removed a static_cast. Seems like it's a win.

llvm-svn: 233748
2015-03-31 20:31:48 +00:00
Rui Ueyama b99d9a0a81 Remove "_hexagon" prefix from some member variables.
At least in Mips we don't have a prefix for member variables.
Repeating the architecture is verbose.

llvm-svn: 233746
2015-03-31 20:29:08 +00:00
Rui Ueyama d3eee4c95c Replace *(uniqueptr.get()) with *uniqueptr.
Apparently they are copy-pastes. They need to be merged, or otherwise
they will diverge needlessly as I did in r233723...

llvm-svn: 233741
2015-03-31 19:55:39 +00:00
Rui Ueyama 73ee010d2d Use C++ non-static member initialization.
llvm-svn: 233739
2015-03-31 19:37:33 +00:00
Rui Ueyama 1f0cd04df9 Rename _AArch64TargetLayout.
This change should have been done in r233737, but I made a mistake to
not include into that.

llvm-svn: 233738
2015-03-31 19:35:35 +00:00
Rui Ueyama efaf6a77d1 Rename identifiers starting with an underscore and a uppercase letter.
Identifiers starting with _[A-Z] is reserved for the language.
User programs shouldn't use such identifiers.

llvm-svn: 233737
2015-03-31 19:33:25 +00:00
Rui Ueyama 537287041b Remove virtual and add override.
llvm-svn: 233735
2015-03-31 19:21:43 +00:00
Simon Atanasyan f00d85a809 [Mips] Use llvm::make_unique
No functional changes.

llvm-svn: 233727
2015-03-31 19:00:54 +00:00
Rui Ueyama 2b28b59311 If x is a unique_ptr, *x.get() is equivalent to *x.
llvm-svn: 233723
2015-03-31 18:26:31 +00:00
Rui Ueyama 07269cc91d Use llvm::make_unique.
llvm-svn: 233721
2015-03-31 18:19:06 +00:00
Rui Ueyama 6814d4f52d ELF: Replace a macro with an inlined function.
FINDV4BITMASK macro is defined as a macro so that the macro body is inlined.
We should use inlined functions instead of macros.

llvm-svn: 233719
2015-03-31 18:15:05 +00:00
Rui Ueyama ace9717a9b ELF: Do not use multiple inheritance.
Multiple inheritance is casually used here. Rewriting to not
using multiple inheritance reduces the complexity of the code
and also makes it shorter.

llvm-svn: 233718
2015-03-31 18:10:24 +00:00
Rui Ueyama c351f9563a Use DEBUG_TYPE and DEBUG instead of DEBUG_WITH_TYPE.
llvm-svn: 233710
2015-03-31 16:48:57 +00:00
Simon Atanasyan 1b2a089951 [Mips] Remove redundant #include
No functional changes.

llvm-svn: 233692
2015-03-31 13:04:08 +00:00
Simon Atanasyan cb576ef415 [Mips] Move the `Elf_RegInfo` structure declaration to the separate file
No functional changes.

llvm-svn: 233618
2015-03-30 22:36:07 +00:00
Simon Atanasyan 2693b5a36c [ELF] Change type of `OutputSection::setType()` argument to int64_t
Type of `OutputSection::_type` field is int64_t. This change makes
the field's and the argument's types consistent and allows to assign
full range of values to the `OutputSection::_type` field.

llvm-svn: 233617
2015-03-30 22:36:01 +00:00
Simon Atanasyan d484653fed [Mips] clang-format the code
No functional changes.

llvm-svn: 233616
2015-03-30 22:35:56 +00:00
Simon Atanasyan 8d08bb2154 [ELF] Use override keyword instead of virtual
No functional changes.

llvm-svn: 233550
2015-03-30 15:07:16 +00:00
Simon Atanasyan 6dec97f2c3 [Mips] Do not use llvm::Optional for GP0 value and TLS section address
Use of llvm::Optional is redundant here. Initializing by default value 0
is enough.

No functional changes.

llvm-svn: 233549
2015-03-30 15:07:11 +00:00
Simon Atanasyan a341e38e39 [Mips] Rename class method merge => mergeHeaderFlags
No functional changes.

llvm-svn: 233548
2015-03-30 15:07:05 +00:00
Simon Atanasyan f9db164355 [Mips] Fix writing R_MIPS_REL32 relocation addendum
If input relocation records have RELA format while output dynamic
relocations have REL format the only way to transfer a dynamic
relocation addendum is to save it into the location modified by
the dynamic relocation.

llvm-svn: 233532
2015-03-30 11:39:02 +00:00
Rui Ueyama 4757f3210c ELF: Use C++11 non-member initialization.
Setting _alignment member varaible to 0 look suspicious since
the minimum alignment value is 1. I'm not going to change that
number in this patch, though.

llvm-svn: 233472
2015-03-28 04:17:41 +00:00
Rui Ueyama aedd1117e9 ELF: Add a comment about the sysroot path.
llvm-svn: 233461
2015-03-28 00:59:37 +00:00
Rui Ueyama 483f05f49b ELF: Do less if HAVE_CXXABI_H is not defined.
If HAVE_CXXABI_H is not defined, this function is the identity function.
Because HAVE_CXXABI_H did not protect the entire function, it did
extra stuffs before returning the argument.

The new code calls fewer functions. This should help developers understand
this piece of code.

llvm-svn: 233460
2015-03-28 00:47:13 +00:00
Rui Ueyama fa3e8979a5 ELF: make code concise using "using".
llvm-svn: 233458
2015-03-28 00:34:09 +00:00
Rui Ueyama 034f627838 Use cast instead of dyn_cast in combination with llvm_unreachable.
llvm-svn: 233456
2015-03-28 00:09:26 +00:00
Rui Ueyama 6fab3c73b8 Use lambda for std::find_if.
llvm-svn: 233454
2015-03-28 00:00:09 +00:00
Rui Ueyama 286494717f Remove else after return.
llvm-svn: 233453
2015-03-27 23:50:09 +00:00
Rui Ueyama ccaaa21bc9 Use lambda instead of defining a class with operator().
llvm-svn: 233452
2015-03-27 23:47:01 +00:00
Rui Ueyama cefe5d678d ELF: make scopes of error code varaibles narrower.
llvm-svn: 233450
2015-03-27 23:30:38 +00:00
Rui Ueyama 5332ba8bea ELF: Simplify SymbolFile.
llvm-svn: 233449
2015-03-27 23:26:39 +00:00
Rui Ueyama b531fe33d5 ELF: Use C++11 non-member initialization.
llvm-svn: 233434
2015-03-27 22:10:29 +00:00
Rui Ueyama 89616adb0c Use override keyword instead of virtual.
llvm-svn: 233424
2015-03-27 21:39:15 +00:00
Rui Ueyama 988355c3ae Remove empty constructors.
llvm-svn: 233423
2015-03-27 21:39:13 +00:00
Rui Ueyama 96278ff759 Fix formatting.
llvm-svn: 233418
2015-03-27 20:50:56 +00:00
Rui Ueyama 194c21209f Remove dead code.
I actually spend my time to understand this piece of code
and then realized that this is all dead.

llvm-svn: 233417
2015-03-27 20:50:54 +00:00
Rui Ueyama 7b57cef5b0 ELF: Add override.
Some virtual member functions in ELF directory don't have
virtual type specifier. Add override to them.

llvm-svn: 233406
2015-03-27 20:15:46 +00:00
Rui Ueyama 674aaaa367 ELF: Remove blank doPreFlight and finalize member functions.
Make these functions non-pure and define the default implementations.

llvm-svn: 233405
2015-03-27 20:15:44 +00:00
Rui Ueyama 52cd43e187 Fix formatting.
llvm-svn: 233402
2015-03-27 19:46:52 +00:00
Rui Ueyama 395b21e192 Rename all caps class names.
We have GOTAtom and PLTAtom classes because GOT or PLT are acronyms.
"Dynamic offset table" or "dynamic" are not acronyms.

llvm-svn: 233401
2015-03-27 19:33:05 +00:00
Rui Ueyama 4f694c873a Remove this->.
llvm-svn: 233400
2015-03-27 19:33:02 +00:00
Denis Protivensky 7eda022521 [ARM] Handle GOT relocations
This includes relocs needed to link against glibc:
R_ARM_BASE_PREL
R_ARM_GOT_BREL

Every reloc is accompanied with a test case.

llvm-svn: 233383
2015-03-27 16:29:08 +00:00
Denis Protivensky 4bdaefdcbe [ARM] Simplify IFUNC code by removing useless handler
llvm-svn: 233374
2015-03-27 12:41:36 +00:00
Denis Protivensky a6e7516ad9 [ARM] Add more IFUNC handlers
llvm-svn: 233372
2015-03-27 12:19:33 +00:00
Rui Ueyama c9ee4de6ca Rename ELFLinkingContext instances "ctx" intead of "context".
llvm-svn: 233344
2015-03-27 01:36:17 +00:00
Rui Ueyama 8b95afa095 Use llvm::make_unique.
llvm-svn: 233319
2015-03-26 21:16:26 +00:00
Rui Ueyama d97b9d8999 Remove duplicate code and empty classes.
llvm-svn: 233316
2015-03-26 21:01:13 +00:00
Rui Ueyama 24f2d2a9d5 Remove Makefiles.
Most developers prefer to not have them, and we agreed to
remove them from LLD.
http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-March/083368.html

llvm-svn: 233313
2015-03-26 20:09:47 +00:00
Leny Kholodov 28074d6e9b [ARM] Implementation of PLT: handling of IFUNC calls (gnu_indirect_function)
This diff includes implementation of linking calls to ifunc functions.
It provides ifunc entries in PLT and corresponding relocations (R_ARM_ALU_PC_G0_NC,
R_ARM_ALU_PC_G1_NC, R_ARM_LDR_PC_G2 for link-time and R_ARM_IRELATIVE for run-time).

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

llvm-svn: 233277
2015-03-26 14:57:50 +00:00
Leny Kholodov 4fdbf55730 Revert blank line after test commit
llvm-svn: 233268
2015-03-26 10:44:14 +00:00
Leny Kholodov 1d01cc7c1b Commit access verification: blank line has been added
llvm-svn: 233267
2015-03-26 10:37:53 +00:00
Denis Protivensky 9e473d0929 [ARM] Handle mapping symbols
Mapping symbols should have their own code models,
and in some places must be treated in a specific way.
Make $t denote Thumb code, and $a and $d denote ARM code.
Set size, binding and type of mapping symbols to what the specification says.

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

llvm-svn: 233259
2015-03-26 07:47:16 +00:00
Rui Ueyama da74d57edb Rename align2 -> align.
I believe "2" stands for log2. Just "align" would be appropriate now.

llvm-svn: 233248
2015-03-26 02:23:45 +00:00
Rui Ueyama 39eb6db9a5 Store non-log2 values to Native files.
llvm-svn: 233247
2015-03-26 02:23:42 +00:00
Rui Ueyama 629f964d50 Use arithmetic type to represent alignments (not in log2) everywhere.
This is the final step of conversion. Now log2 numbers are removed
from everywhere!

llvm-svn: 233246
2015-03-26 02:20:25 +00:00
Rui Ueyama f217ef0d75 Use alignment values everywhere instead of log2.
This patch defines implicit conversion between integers and PowerOf2
instances, so uses of the classes is now implicit and look like
regular integers. Now we are ready to remove the scaffolding.

llvm-svn: 233245
2015-03-26 02:03:44 +00:00
Rui Ueyama f006f4d62c Define an implicit constructor which takes actual alignment value to PowerOf2.
The new constructor's type is the same, but this one takes not a log2
value but an alignment value itself, so the meaning is totally differnet.

llvm-svn: 233244
2015-03-26 01:44:01 +00:00
Rui Ueyama 48865ca64d Make PowerOf2's constructor private.
Ban conversion from integers to PowerOf2 even if explicit
to make all places we create PowerOf2 instances visible.

llvm-svn: 233243
2015-03-26 01:29:06 +00:00
Rui Ueyama c3d18f5120 Remove implicit constructor and operator int from PowerOf2.
This patch is to make instantiation and conversion to an integer explicit,
so that we can mechanically replace all occurrences of the class with
integer in the next step.

Now get() returns an alignment value rather than its log2 value.

llvm-svn: 233242
2015-03-26 01:12:32 +00:00
Rui Ueyama d2c1bf638b Add a scaffolding to merge alignment representations.
We are using log2 values and values themselves to represent alignments.
For example, alignment 8 is sometimes represented as 3 (8 == 2^3).
We want to stop using log2 values.

Because both types are regular arithmetic types, we cannot get help from
a compiler to find places we mix two representations. That makes this
merging work surprisingly hard because if I make a mistake, I'll just get
wrong results at runtime (Yay types!). In this patch, I introduced
a class to represents power-of-two values, which is basically an alias
for an integer type.

Once the migration is done, the class will be removed.

llvm-svn: 233232
2015-03-26 00:10:50 +00:00
Rui Ueyama 533849c615 YAML: Do not use 2^x notation to represent alignments.
llvm-svn: 233222
2015-03-25 22:06:04 +00:00
Rui Ueyama 2977772f54 Use llvm::isPowerOf2. NFC.
llvm-svn: 233219
2015-03-25 21:21:57 +00:00
Rui Ueyama aa9cd48e2b Inherit constructors. No functionality change.
We cannot use "using" to inherit constructors because the feature
is not supported by MSVC 2013.

llvm-svn: 233218
2015-03-25 21:20:11 +00:00
Simon Atanasyan 235838e1b8 [Mips] Factor out the code that extracts a relocation 'tag' into
the separate function

That keeps "extracting" logic into the single place and removes a VC++
compilation warning.

llvm-svn: 233186
2015-03-25 13:12:59 +00:00
Rui Ueyama c756b2dfac PECOFF: Reduce import table size.
Import Lookup Table in Import Directory Table has the same contents
as Hint/Name Table. Symbol names imported from DLLs are pointed by
both Import Directory Table and Hint/Name Table. We had duplicate
strings there.

This patch eliminates that duplication to make the table smaller.
This should reduce binary size by the sum of lengths of imported
symbols.

llvm-svn: 233128
2015-03-24 22:43:58 +00:00
Simon Atanasyan d13587f671 [Mips] Suppress "right shift by too large amount" warning
Visual C++ shows the "right shift by too large amount" warning if
`MipsELFReference` is instantiated for 32-bit target and `Elf_Rel_Impl::getType`
method has `unsigned char` return type. We can freely suppress the warning in
that case because MIPS 32-bit ABI does not pack multiple relocation types into
the single field `r_type` and the `MipsELFReference::_tag` should be always
zero in that case.

No functional changes.

llvm-svn: 233088
2015-03-24 15:49:59 +00:00