Commit Graph

3156 Commits

Author SHA1 Message Date
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
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 b2d1c0c09c [Mips] Add checking of .reginfo section options to the test case
llvm-svn: 234114
2015-04-05 09:01:35 +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
Denis Protivensky ee3261834e [ARM] Avoid potential error in test because of name collision
llvm-svn: 234001
2015-04-03 08:03:23 +00:00
Denis Protivensky c04fbb7340 [ARM] Test wrong ARM entry point address align
llvm-svn: 234000
2015-04-03 07:57:27 +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 514db75180 ELF: Update comments.
This patch updates comments in the ELFLinkingContext to use
non-question sentences as brief descriptions of functions.

llvm-svn: 233774
2015-04-01 00:31:41 +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 0d26edab09 [Mips] Do not use MIPS assembler and disassembler in the tests
No functional changes.

llvm-svn: 233691
2015-03-31 13:04:01 +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
Denis Protivensky 48906062df [ARM] Remove whitespace in rel-ifunc test
llvm-svn: 233538
2015-03-30 13:31: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
Leny Kholodov 4ba377561f [ARM] Fix group relocations test.
The fix is for r233277. This makes tests work.
On some build bots the test failed due to different llvm-objdump behaviour for target detection.
Now test checks .text section with etalon and illustrates correctness of generated
code without using of -disassemble llvm-objdump option.

llvm-svn: 233463
2015-03-28 01:18:10 +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 49147e30f8 Remove unused forward declaration.
llvm-svn: 233444
2015-03-27 22:59:26 +00:00
Rui Ueyama d5c60d032f ELF: Use llvm::Optional<StringRef> instead of a bool and a StringRef.
llvm-svn: 233442
2015-03-27 22:51:50 +00:00
Rui Ueyama a57f619133 Remove virtual from some ELFLinkingContext member functions.
I expected that these functions are overridden somewhere in the LLD
code base, but they are actually not. Removing virtual for readability
(and performance).

llvm-svn: 233441
2015-03-27 22:47:44 +00:00
Rui Ueyama 0de4ab513f Reorder ELFLinkingContext member functions and run clang-format.
So that they look to be following the same style as other functions
around them.

llvm-svn: 233440
2015-03-27 22:47:42 +00:00
Rui Ueyama a2ddf07f25 ELF: Do not use llvm::Optional for _maxPageSize.
Use of llvm::Optional seems useless here because we can set the
default value 0x1000 as an initial value to the varaible.
This patch also de-virtualize the accessor functions.

llvm-svn: 233438
2015-03-27 22:28:35 +00:00
Rui Ueyama c470444837 Fix comment style to follow more common style.
llvm-svn: 233437
2015-03-27 22:28:33 +00:00
Rui Ueyama e555684115 ELF: Make addSearchPath return void instead of bool.
No one uses return value of the member function, and return value
is always true. Returning a value doesn't make sense.
This patch also de-virtualize the fucntion.

llvm-svn: 233436
2015-03-27 22:20:21 +00:00
Rui Ueyama 9cced88c7a ELF: Remove redundant =delete.
Since we have a (protected) constructor having two parameters,
the default constructor is not defined even if we don't do =delete.

llvm-svn: 233435
2015-03-27 22:13:29 +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 adef19778c Remove unused varaible.
llvm-svn: 233433
2015-03-27 22:06:37 +00:00
Rui Ueyama 2d6d7efb00 PECOFF: Use C++11 non-static member initialization.
llvm-svn: 233431
2015-03-27 21:59:23 +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 ab57d42dea [ARM] Fix PLT IFUNC symbol names in Release build
The fix is for r233277.
This makes tests work.

llvm-svn: 233280
2015-03-26 15:44:19 +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 103e03040b Add a test for r233128: PECOFF: Reduce import table size.
This test checks for the size of .idata section. Before r233128,
the size of the section is 0x45, but it's now 0x27.

llvm-svn: 233154
2015-03-25 00:18:16 +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
Simon Atanasyan 396ce8fbe0 [Mips] Do not use inheriting constructor due build problem on Windows
No functional changes.

llvm-svn: 233058
2015-03-24 10:25:21 +00:00
Simon Atanasyan 623d3b0043 [Mips] Support MIPS N64 relocation record format
N64 ABI relocation record r_info field in fact consists of five subfields:
* r_sym   - symbol index
* r_ssym  - special symbol
* r_type3 - third relocation type
* r_type2 - second relocation type
* r_type  - first relocation type

Up to three these relocations applied one by one. The first relocation
uses an addendum from the relocation record. Each subsequent relocation
takes as its addend the result of the previous operation. Only the final
operation actually modifies the location relocated. The first relocation
uses as a reference symbol specified by the `r_sym` field. The third
relocation assumes NULL symbol.

The patch represents these data using LLD model and takes in account
additional relocation types during a relocation calculation.

Additional relocations do not introduce any new relations between two
atoms and just specify operations need to be done during a relocation
calculation. The first relocation type (`r_type`) stored in the
`Reference::_kindValue`. The rest of relocations and `r_ssym` value are
stored in the new `Reference::_tag` field "as-is". I decided to do not
"decode" these data on the core LLD level to prevent pollution of the
core LLD model by very target specific data.

Also I have to override writing of relocation records in the `RelocationTable`
class to convert MIPS N64 ABI relocation information from the `Reference`
class back to the ELF relocation record.

http://reviews.llvm.org/D8533

llvm-svn: 233057
2015-03-24 09:57:05 +00:00
Simon Atanasyan 25122a3c57 [Mips] Fix typo in the error message
llvm-svn: 233054
2015-03-24 09:05:35 +00:00
Davide Italiano 20f3da11e8 [ELF/X86_64] Fix handling of R_X86_64_GOTTPOFF relocation.
The aforementioned relocation generate a GOT entry with a
R_X86_64_TPOFF64. The new relocation is processed at startup
time by the loader. lld didn't generate the outstanding relocation,
now it does. This bug was found while trying to link ls(1) on FreeBSD.

Simplified repro:
#include <stdio.h>
#include <wchar.h>
#include <wctype.h>

int
main(void)
{
    wchar_t wc = 98;
    if (!iswprint(wc))
        printf("blah\n");
    else
        printf("foo\n");
    return (0);
}

which incorrectly outputs "blah" when linked with lld before this patch.

llvm-svn: 233051
2015-03-24 06:22:45 +00:00
Rafael Auler 515fd61692 [ELF] Remove extraneous semicolon in DefaultLayout
llvm-svn: 232985
2015-03-23 18:39:37 +00:00
Benjamin Kramer e13f47e8aa Fix the CMake shared build.
The ELF backends now depend on lld::script::Sema, which is in libReaderWriter.
Link it explicitly.

llvm-svn: 232953
2015-03-23 15:55:00 +00:00
Denis Protivensky a2e5b2cea7 [ARM] Fix entry point for Thumb code
Test cases for both entry functions in ARM and Thumb
code are added.

llvm-svn: 232942
2015-03-23 11:38:24 +00:00
Simon Atanasyan 5d82380e82 [ELF] Add missing override keyword
No functional changes.

llvm-svn: 232938
2015-03-23 10:33:46 +00:00
Simon Atanasyan 283629a0f7 [Mips] Pass type of relocation and addendum to the `calculateRelocation`
separately

This change reduce difference between the trunk and upcoming patch and
simplify the future code review.

No functional changes.

llvm-svn: 232919
2015-03-22 16:35:08 +00:00
Simon Atanasyan 73fef59b20 [Mips] Rename template argument ELFType => ELFT
No functional changes.

llvm-svn: 232915
2015-03-22 15:41:16 +00:00
Simon Atanasyan 579fde1d83 [Mips] Use allocator from the base class
No functional changes.

llvm-svn: 232914
2015-03-22 15:41:10 +00:00
Shankar Easwaran 37d5add8a3 [ELF] GLOBAL_OFFSET_TABLE is a hidden symbol
llvm-svn: 232868
2015-03-20 23:47:08 +00:00
Shankar Easwaran 14726cd11b [ELF] Dont add local symbols for dynamic lookup.
Unable to add a unit test for this, as there is only one local undefined
symbol in regular shared libraries without a name.

llvm-svn: 232867
2015-03-20 23:47:05 +00:00
Shankar Easwaran 07f6ce0b83 [ELF] OrderPass : Order atoms only by ordinals.
Move the init array/fini array sorting to the Output ELF writer.

AFAIK, this is only needed by the X86_64/ARM ABI.

This shaves time taken to self host lld by 0.2 seconds.

Before patch
----------------
4791.062059 task-clock                #    1.634 CPUs utilized            ( +-  0.28% )
     61,107 context-switches          #    0.013 M/sec                    ( +-  0.56% )
2.932902671 seconds time elapsed                                          ( +-  0.84% )

After patch
-------------
4608.417248 task-clock                #    1.669 CPUs utilized            ( +-  0.30% )
     61,616 context-switches          #    0.013 M/sec                    ( +-  0.63% )
2.761012703 seconds time elapsed                                          ( +-  0.63% )

llvm-svn: 232866
2015-03-20 23:47:03 +00:00
Shankar Easwaran 33c979d685 [ELF][X86_64] Use anonymous namespace only for class declarations
llvm-svn: 232865
2015-03-20 23:47:01 +00:00
Shankar Easwaran b9c3bacb3b [ELF] Use unordered_map for AdditionalSegments
Fix a leftover class during implementation.

llvm-svn: 232864
2015-03-20 23:47:00 +00:00
Shankar Easwaran 1f869d0e1a [ELF] Use MapVector.
Order is still deterministic and we dont need a sorted order.

llvm-svn: 232863
2015-03-20 23:46:58 +00:00
Shankar Easwaran 208ac3d6e5 [ELF][X86_64] Remove relative references to include files
llvm-svn: 232862
2015-03-20 23:46:56 +00:00
Shankar Easwaran f65b60e806 [ELF][X86_64] Sort includes
llvm-svn: 232861
2015-03-20 23:46:54 +00:00
Simon Atanasyan 12e9f8cd11 [Mips] Create special PLT entry in case of MIPS R6 ABI
llvm-svn: 232806
2015-03-20 11:28:22 +00:00
Simon Atanasyan c823c9523c [Mips] Add comments to the relocation calculation functions
No functional changes.

llvm-svn: 232761
2015-03-19 20:56:34 +00:00
Simon Atanasyan caadcc3f27 [Mips] Implement R_MIPS_PCHI16 / R_MIPS_PCLO16 relocations handling
llvm-svn: 232757
2015-03-19 19:59:17 +00:00
Simon Atanasyan 48e088f354 [Mips] Implement R_MIPS_PC18_S3 relocation handling
llvm-svn: 232756
2015-03-19 19:59:06 +00:00
Simon Atanasyan 5472ea1270 [Mips] Implement R_MIPS_PC19_S2 / R_MIPS_PC26_S2 relocations handling
llvm-svn: 232755
2015-03-19 19:58:58 +00:00
Denis Protivensky 91141e87b1 [ARM] Implement static (initial exec) TLS model
This includes handling of R_ARM_TLS_IE32 and R_ARM_TLS_LE32 relocs.

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

llvm-svn: 232708
2015-03-19 06:47:44 +00:00
Simon Atanasyan 14afb83952 [Mips] Implement R_MIPS_PC21_S2 relocation handling
llvm-svn: 232707
2015-03-19 05:44:22 +00:00
Simon Atanasyan 14b5217cc6 [Mips] Recognize and check compatibility MIPS32R6 / MIPS64R6 ISA's
llvm-svn: 232706
2015-03-19 05:44:13 +00:00
Simon Atanasyan 8343c2c9ec [Mips] Replace "hand-made" function by the `llvm::SignExtend32()` routine
No functional changes.

llvm-svn: 232705
2015-03-19 05:44:04 +00:00
Rui Ueyama ddf77ce2bf PECOFF: Do not copy all undefined symbols to a set. NFC.
llvm-svn: 232646
2015-03-18 16:28:33 +00:00
Rui Ueyama 8cc20307e1 Remove unused parameter.
llvm-svn: 232639
2015-03-18 15:12:55 +00:00
Shankar Easwaran f06086a912 [ELF][ARM] Place gotSymbol in an anonymous namespace
Address comments from Espindola.

llvm-svn: 232497
2015-03-17 16:40:14 +00:00
Denis Protivensky 5a106191fa [ARM] Read initial addend for REL32 and PREL31 relocs
llvm-svn: 232474
2015-03-17 13:51:32 +00:00
Denis Protivensky e458ab4577 [ARM] Implement relocations: R_ARM_REL32, R_ARM_THM_JUMP11, R_ARM_PREL31
Test case for every relocation is added.

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

llvm-svn: 232464
2015-03-17 09:18:24 +00:00
Shankar Easwaran baf1aaaf1f [ELF] Use parallel_for_each for writing.
This changes improves performance of lld, when self-hosting lld, when compared
with the bfd linker. BFD linker on average takes 8 seconds in elapsed time.
lld takes 3 seconds elapased time average. Without this change, lld takes ~5
seconds average. The runtime comparisons were done on a release build and
measured by running linking thrice.

lld self-host without the change
----------------------------------
real    0m3.196s
user    0m4.580s
sys     0m0.832s

lld self-host with lld
-----------------------
user    0m3.024s
user    0m3.252s
sys     0m0.796s

time taken to build lld with bfd
--------------------------------
real    0m8.419s
user    0m7.748s
sys     0m0.632s

llvm-svn: 232460
2015-03-17 03:29:32 +00:00
Rui Ueyama cc6b381651 Make it compile with MSVC 2013.
MSVC 2013 cannot compile this code because of C1001 "internal error".
Stop using initializer list without type name.

llvm-svn: 232448
2015-03-17 01:10:12 +00:00
Rui Ueyama 3c2e306a5c PECOFF: Make FileCOFF:findAtomAt from O(n) to O(1).
I knew I cut corners when I wrote this. Turned out that it is
actually slow when a file being read has many symbols. This patch
is to stop doing linear search and instead do map lookup.

llvm-svn: 232436
2015-03-16 23:43:11 +00:00
Shankar Easwaran 9b7374b821 [Core] Add parallel_for_each
This adds a parallel_for_each similar to functionality in MSVC concurrency
library.

This was very patiently reviewed by Rui and credits go to him for this patch.

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

llvm-svn: 232419
2015-03-16 21:27:32 +00:00
Simon Atanasyan 4b4706b601 [ELF] Use pcrel format for eh_frame_ptr field encoding
The `eh_frame_ptr` field in the `.eh_frame_hdr` section contains an address
of the `.eh_frame` section. Using an absolute 32-bit format for encoding
of this field does not work for 64-bit targets. It is better to use a
relative format because it covers both 32-bit and 64-bit cases. Sure
this work if a distance between `.eh_frame_hdr` and `.eh_frame` sections
is less than 4 Gb but it is a rather correct assumption.

http://reviews.llvm.org/D8352

llvm-svn: 232414
2015-03-16 21:07:46 +00:00
Rafael Auler 01d73c9678 [LinkerScript] Handle symbols defined in linker scripts
Puts symbols defined in linker script expressions in a runtime file that is
added as input to the resolver, making the input object files see symbols
defined in linker scripts.

http://reviews.llvm.org/D8263

llvm-svn: 232409
2015-03-16 20:39:07 +00:00
Rafael Auler 8dd680dcb1 [LinkerScript] Adding test cases for SECTIONS semantics
llvm-svn: 232404
2015-03-16 19:56:42 +00:00
Rafael Auler 9a7e211e8f [LinkerScript] Implement semantics for simple sections mappings
This commit implements the behaviour of the SECTIONS linker script directive,
used to not only define a custom mapping between input and output sections, but
also order input sections in the output file. To do this, we modify
DefaultLayout with hooks at important places that allow us to re-order input
sections according to a custom order. We also add a hook in SegmentChunk to
allow us to calculate linker script expressions while assigning virtual
addresses to the input sections that live in a segment.

Not all SECTIONS constructs are currently supported, but only the ones that do
not use special sort orders. It adds two LIT test as practical examples of
which sections directives are currently supported.

In terms of high-level changes, it creates a new class "script::Sema" that owns
all linker script ASTs and the logic for linker script semantics as well.
ELFLinkingContext owns a single copy of Sema, which will be used throughout
the object file writing process (to layout sections as proposed by the linker
script).

Other high-level change is that the writer no longer uses a "const" copy of
the linking context. This happens because linker script expressions must be
calculated *while* calculating final virtual addresses, which is a very late
step in object file writing. While calculating these expressions, we need to
update the linker script symbol table (inside the semantics object), and, thus,
we are "modifying our context" as we prepare to write the file.

http://reviews.llvm.org/D8157

llvm-svn: 232402
2015-03-16 19:55:15 +00:00
Simon Atanasyan 3c1818c8c0 [Mips] clang-format the code
No functional changes.

llvm-svn: 232364
2015-03-16 09:14:47 +00:00
Simon Atanasyan a1abb2e2c7 [Mips] Do not check the relocation type twice
No functional changes.

llvm-svn: 232363
2015-03-16 09:14:40 +00:00
Simon Atanasyan 622a4bc83b [Mips] Add `const` qualifier to some member functions
No functional changes.

llvm-svn: 232362
2015-03-16 09:14:34 +00:00
Simon Atanasyan 44e9b094e0 [Mips] Implement R_MIPS_TLS_xxx relocation handling in case of N64 ABI
llvm-svn: 232361
2015-03-16 09:14:28 +00:00
Simon Atanasyan 256407d9e2 [Mips] Implement R_MIPS_GOT_DISP/PAGE/OFST relocations handling
llvm-svn: 232360
2015-03-16 09:14:17 +00:00
Simon Atanasyan 08b19d67fa [Mips] Group some cases in the switch statement
No functional changes.

llvm-svn: 232359
2015-03-16 09:14:06 +00:00
Shankar Easwaran 9fdb81d09b [ELF][ARM] Make gotSymbol a member.
The gotSymbol need not be a global static variable. Apart from this reason, This
variable was creating an issue with self hosting lld, as there seems to be an
issue running global initializers, when initializing the guard for this static
variable.

Program received signal SIGTRAP, Trace/breakpoint trap.

llvm-svn: 232341
2015-03-16 00:54:03 +00:00
Davide Italiano de42c18889 Use setVisibility() rather than assigning the value directly.
We don't want to risk to override wrong st_other bits, and when
we need to zero, we can do that explictly.

llvm-svn: 232282
2015-03-14 21:57:15 +00:00
Shankar Easwaran 5d34ad79b4 Revert "[ELF] Change few static functions."
This reverts commit r232253.

Fix comments from dblaikie. Since these functions dont access member state, its ok to be static.

llvm-svn: 232271
2015-03-14 19:41:24 +00:00
Denis Protivensky cd61715564 [ELF] Ability to resolve undefined symbols lazily
Handle resolution of symbols coming from linked object files lazily.
Add implementation of handling _GLOBAL_OFFSET_TABLE_ and __exidx_start/_end symbols for ARM platform.

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

llvm-svn: 232261
2015-03-14 10:34:43 +00:00
Shankar Easwaran 6d812fa9ca [ELF] Change few static functions.
Functions hasOutputSegment/maybeGetSOName doesnot need not be static.

llvm-svn: 232253
2015-03-14 05:27:01 +00:00
Shankar Easwaran 48578e7124 [ELF] Rename .got.dyn to .got
Gnu doesnot creates only a .got section.

llvm-svn: 232252
2015-03-14 05:26:58 +00:00
Shankar Easwaran c1e146e024 [ELF] Fix DenseMapInfo for StringRef
llvm-svn: 232251
2015-03-14 05:26:55 +00:00
Shankar Easwaran 9f9f2ddb86 [ELF] Remove ambiguity
Fix ambiguous finalize function.

llvm-svn: 232250
2015-03-14 05:26:53 +00:00
Shankar Easwaran 729a79a1c4 [ELF] Simplify appending chunks to segments.
The Segment Chunk had two functions one to append a section and one to append a
chunk. A section is a subclass of a chunk and clearly this can be merged into
one single function.

llvm-svn: 232249
2015-03-14 05:26:50 +00:00
Rui Ueyama 65c1704604 Windows: Include <eh.h> instead of declarating __uncaught_exception.
llvm-svn: 232204
2015-03-13 19:52:39 +00:00
Meador Inge 84f613532f LinkerScript: Add -T <scriptfile> option
GNU LD has an option named -T/--script which allows a user to specify
a linker script to be used [1].  LLD already accepts linker scripts
without this option, but the option is widely used.  Therefore it is
best to support it in LLD as well.

[1] https://sourceware.org/binutils/docs/ld/Options.html#Options

llvm-svn: 232183
2015-03-13 18:15:01 +00:00
Meador Inge 28dac858cd LinkerScript: Add evaluation of the EXTERN command
This patch implements evaluation of the GNU ld EXTERN command.

llvm-svn: 232111
2015-03-12 21:55:55 +00:00
Meador Inge 748a71b8de LinkerScript: Add parsing of the EXTERN command
This patch implements parsing of the GNU ld EXTERN command [1].
Evaluation will be added at a later point in time.

[1] https://sourceware.org/binutils/docs/ld/Miscellaneous-Commands.html#Miscellaneous-Commands

llvm-svn: 232110
2015-03-12 21:55:50 +00:00
David Blaikie f1f52512ea Make the atom_iterator copy assignable
This makes it a bit more like a 'real' iterator though I still haven't
gone through to make sure it meets the full requirements. Copy
assignability seems to be required by MSVC's std::find_if, which is its
right.

llvm-svn: 232097
2015-03-12 20:18:10 +00:00
Renato Golin 7f29cf5770 Update copyright year to 2015.
llvm-svn: 232096
2015-03-12 20:14:35 +00:00
David Blaikie 72da9ae924 Rephrase find loop to use std::find_if
Avoids the need for an assert-only variable, among other benefits.

llvm-svn: 232088
2015-03-12 19:46:21 +00:00
Simon Atanasyan 9a0263aad7 [Mips] Make `readAddend` a virtual member function to escape explicit
template class instantiation

No functional changes.

llvm-svn: 232081
2015-03-12 18:53:06 +00:00
Chris Bieneman d24e65895d Fixing CMake developer warning.
LLDUnitTests target doesn't exist unless LLVM_INCLUDE_TESTS is On.

llvm-svn: 232058
2015-03-12 16:49:52 +00:00
Iain Sandoe 832472a2ad Fix configure & make build by adding support for the ExampleSubTarget.
llvm-svn: 232030
2015-03-12 11:47:51 +00:00
Justin Bogner 14d34ef050 Avoid an unused variable warning when assertions are off
Patch by Mike Edwards. Thanks!

llvm-svn: 232015
2015-03-12 06:50:54 +00:00
Chandler Carruth cd632dc486 Don't rely on the elf test suites inputs when testing the driver. We
already have a perfectly cromulent test archive in the driver inputs.

llvm-svn: 231976
2015-03-11 22:12:40 +00:00
Chandler Carruth 5ad16c2ad0 Move the 'linker-script-test' binary to the tools directory.
The canonical LLVM directory arrangement places binaries in the 'utils/'
tree when they are used as part of building the project. For example,
the tblgen binaries are built out of 'utils/' trees.

Tools which are not used by any other part of the build, including
testing utilities, are just in the 'tools' directory. For example, in
Clang we have 'c-index-test' which is exactly the same kind of thing as
'linker-script-test'.

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

llvm-svn: 231973
2015-03-11 22:05:49 +00:00
Chandler Carruth c9cdc502f3 Fix a comparison function to actually be a SWO so that it conforms to
the spec required by std::sort and friends.

Ordering things this way also dramatically simplifies the code as
short-circuit ensures we can skip all of the negative tests.

I've left one FIXME where we're establishing a fairly arbitrary
ordering. Previously, the function compared all types as equal except
for the ones it explicitly handled, but it didn't delegate correctly to
the atomflags when doing so, and so it would fail to be a SWO. The two
possible fixes are to stop comparing the atom flags entirely, or to
establish some arbitrary ordering of the types.

Since it was pure luck which ordering of unequal types we ended up with
previously (the caller was std::sort, not std::stable_sort) I chose to
make the ordering explicit and guaranteed. This seems like the best
conservative approach as I suspect we would want to switch to
stable_sort otherwise in order to have deterministic output.

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

llvm-svn: 231968
2015-03-11 21:34:33 +00:00
Meador Inge 2ce1ea86d0 LinkerScript: Add parsing of the MEMORY command
This patch implements parsing of the GNU ld MEMORY command [1].
The command and the memory block definitions are parsed as
specified (including the slightly strange "o" and "l" keywords).
Evaluation will be added at a later point in time.

[1] https://sourceware.org/binutils/docs-2.25/ld/MEMORY.html

llvm-svn: 231928
2015-03-11 15:34:44 +00:00
Davide Italiano 243e03d819 Garbage collect an unused class in Atoms.h
This will be replaced by a more generic class to handle
all the default symbols in an executable, e.g. __init_array.

Differential Revision:	 http://reviews.llvm.org/D8234
Reviewed by:	shankare

llvm-svn: 231906
2015-03-11 05:31:07 +00:00
Chandler Carruth 96f02da75a The LLD tests require 'llvm-nm' to run as well, ensure that this is
built before running the test suite.

llvm-svn: 231770
2015-03-10 08:08:58 +00:00
Chandler Carruth 8300c76b15 Don't write output to 'a.out', write it to a temporary file. This fixes
the test when run frem a read-only checkout of the source tree.

llvm-svn: 231769
2015-03-10 08:06:49 +00:00
Chandler Carruth 1bdbf48fff Fix the local variable naming I used in r231765 to follow the LLD coding
conventions. Sorry for missing this before I committed the patch!

llvm-svn: 231766
2015-03-10 07:54:34 +00:00
Chandler Carruth b952e2287b Fix a bug where the code would use subscript a std::vector with the size
of the vector. For a vector 'v', '&v[v.size()]' isn't a valid way to
compute a pointer one-past-the-end of the vector. Instead, write the
loop in terms of iterators and save the beginning iterator. Once we have
that we can compute the beginning pointer from the beginning iterator,
and compute the distance which we should increment the beginning pointer
by subtracting the iterators.

What might be simpler would be to convert the function accepting a raw
pointer for begin and end to accept iterators or a range or some other
construct, but I wanted to keep this to a minimal bug-fix change.

This fixes a crash on any debug STL implementation which checks for
indexing out of bounds.

llvm-svn: 231765
2015-03-10 07:53:02 +00:00
Rui Ueyama 81ad639ed3 Use template aliases.
We dropped Visual Studio 2012 support, so we can use template aliases.

llvm-svn: 231756
2015-03-10 05:14:24 +00:00
Rui Ueyama 4a8821d48d Add SimpleAbsoluteAtom which is analogous to other Simple* atoms.
llvm-svn: 231718
2015-03-09 22:34:59 +00:00
Rui Ueyama bf3ac0b878 Remove COFFReference and use SimpleReference instead.
SimpleReference, which is defined in Core, provides the same functionality
as COFFReference does, so we don't need a custom class.

llvm-svn: 231715
2015-03-09 22:18:51 +00:00
Rafael Auler ad11d4c196 [LinkerScript] Implement linker script expression evaluation
The expression evaluation is needed when interpreting linker scripts, in order
to calculate the value for new symbols or to determine a new position to load
sections in memory. This commit extends Expression nodes from the linker script
AST with evaluation functions, and also contains a unit test.

http://reviews.llvm.org/D8156

llvm-svn: 231707
2015-03-09 21:43:35 +00:00
Rui Ueyama 6a3167d35a Remove dead code.
llvm-svn: 231688
2015-03-09 18:59:55 +00:00
Simon Atanasyan b9a1443576 [Mips] Remove unused include
No functional changes.

llvm-svn: 231646
2015-03-09 10:54:11 +00:00