Commit Graph

3024 Commits

Author SHA1 Message Date
Pete Cooper ab01073765 Add ObjC method list atom type. NFC.
An upcoming patch will use this to create lists of ObjC methods.

Adding it now to reduce the amount of code in that patch.

Test cases will follow in the other patch too.

llvm-svn: 259440
2016-02-01 23:56:27 +00:00
Pete Cooper c2bad09cdd Add command line option to disable ObjC category merging.
This adds the no_objc_category_merging cmdline option which will
be used in an upcoming commit to disable the category optimizer.

It is on by default in ld64 so we match that here.

Test case will come soon with the patch to make use of this option.

llvm-svn: 259439
2016-02-01 23:56:23 +00:00
Pete Cooper f91b22ce2c Move SimpleDefinedAtom::addReference to DefinedAtom.
Most of the other methods to access Reference's were on DefinedAtom so
this just keeps them all together.

This will be used in a future patch in ObjCPass which needs to add
new references.  The method is virtual because we may add references to
different data structures depending on whether we parsed a macho file or
yaml.

llvm-svn: 259436
2016-02-01 23:42:10 +00:00
Pete Cooper 55634d8e8d MachoFile should default to using subsections_via_symbols.
When we parse a MachoFile, we set a number of members from the parsed
file, for example, subsectionsViaSymbols.

However, a number of passes, such as ObjCPass, create local copies of
MachoFile and don't get the benefit of setting flags and other fields in
the parser.  Instead we can just give a more sensible default as the parser
will definitely get the correct value from the file anyway.

llvm-svn: 259426
2016-02-01 22:24:44 +00:00
Pete Cooper d714fc75cd Use dyn_cast instead of static_cast.
Now that MachoFile has classof(), we can use dyn_cast instead which
is actually the only safe way to handle this.

Turns out this actually manifests as a bug as we were incorrectly
casting instances which weren't MachoFile in to a MachoFile.

Unfortunately, there's no reliable way of checking for this as it
requires that the file we are looking for has a 0 at exactly the byte
we need for the load of subsectionsViaSymbols.

llvm-svn: 259413
2016-02-01 21:42:17 +00:00
Pete Cooper 4a92469260 Atomize the ObjC category list section.
__DATA, __objc_catlist contains a list of pointers to categories.

We want to atomize it so that the ObjC pass can later optimize and remove
categories.  That will be a later patch.

llvm-svn: 259386
2016-02-01 19:10:10 +00:00
Rui Ueyama 64cfffd333 ELF: Rename error -> fatal and redefine error as a non-noreturn function.
In many situations, we don't want to exit at the first error even in the
process model. For example, it is better to report all undefined symbols
rather than reporting the first one that the linker picked up randomly.

In order to handle such errors, we don't need to wrap everything with
ErrorOr (thanks for David Blaikie for pointing this out!) Instead, we
can set a flag to record the fact that we found an error and keep it
going until it reaches a reasonable checkpoint.

This idea should be applicable to other places. For example, we can
ignore broken relocations and check for errors after visiting all relocs.

In this patch, I rename error to fatal, and introduce another version of
error which doesn't call exit. That function instead sets HasError to true.
Once HasError becomes true, it stays true, so that we know that there
was an error if it is true.

I think introducing a non-noreturn error reporting function is by itself
a good idea, and it looks to me that this also provides a gradual path
towards lld-as-a-library (or at least embed-lld-to-your-program) without
sacrificing code readability with lots of ErrorOr's.

http://reviews.llvm.org/D16641

llvm-svn: 259069
2016-01-28 18:40:06 +00:00
Pete Cooper e420dd4d84 Use an ilist instead of std::list. NFC.
The TrieNode/TrieEdge data structures here are allocated in a bumpptrallocator.

Unfortunately, TrieNode contained a std::list<TrieEdge> and as the allocator doesn't
call the TrieNode destructor, we ended up leaking the memory allocated by the std::list
itself.

Instead we can use an intrusive list as then we save the extra allocations anyway.

llvm-svn: 258725
2016-01-25 21:50:54 +00:00
Pete Cooper 580ccca192 Initialize member variable.
Found by Rafael using valgrind in https://llvm.org/bugs/show_bug.cgi?id=21466.

llvm-svn: 258718
2016-01-25 20:41:48 +00:00
Pete Cooper 351164504a Add support for export_dynamic cmdline option and behaviour.
This option matches the behaviour of ld64, that is it prevents globals
from being dead stripped in executables and dylibs.

Reviewed by Lang Hames

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

llvm-svn: 258554
2016-01-22 21:13:24 +00:00
Pete Cooper 90dbab0b0d Add an ObjCPass to the MachO linker.
This pass currently emits an objc image info section if one is required.

This section contains the aggregated version and flags for all of the input
files.

llvm-svn: 258197
2016-01-19 21:54:21 +00:00
Pete Cooper 0872e46c9d Set the objc constraint on the context based on the parsed files.
Like arch, os, etc, when we know we are going to use a file, we check
that the file has compatible objc constraints to the context, throw
appropriate errors where that is not the case, and hopefully set the
objc constraints on the context for use later.

Added 2 tests to ensure that we don't have incompatibilities between
host and simulator code as both will get x86 based architectures.

llvm-svn: 258173
2016-01-19 19:46:41 +00:00
Pete Cooper feaa967ee8 Cache the objc image info constraints in file.
Image info flags describe the objc constraint which is GC/retain/release/etc.

These need to be parsed and stored in the file so that we can do error checking.

That will come in a later commit.

llvm-svn: 258160
2016-01-19 18:46:40 +00:00
Pete Cooper 12b094d5f4 Only emit files with subsections_via_symbols if all inputs had that set.
When generating a relocatable file, its only valid to set this flag if
all of the inputs also had the flag.  Otherwise we may atomize incorrectly
when we link the relocatable file again.

Reviewed by Lang Hames.

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

llvm-svn: 257976
2016-01-16 01:09:23 +00:00
Pete Cooper 4b6bed98e2 Give error on binaries containing GC objc image infos.
The image info struct contains flags for what kind of GC/retain/release is required.

Give an error if we parse GC flags as these are unsupported.

llvm-svn: 257974
2016-01-16 00:57:07 +00:00
Pete Cooper a014ffef87 Add checking of differing swift versions in input files.
Swift versions are part of the objc image info section, and must match
for all files linked which actually have an image info section

llvm-svn: 257964
2016-01-16 00:07:22 +00:00
Pete Cooper 20de822232 Check that the objc image info version is exactly 0
llvm-svn: 257953
2016-01-15 23:25:37 +00:00
Pete Cooper 2735783090 Add the GC commandline options and throw errors if they are used
llvm-svn: 257907
2016-01-15 17:39:02 +00:00
Pete Cooper d7b5c5bcef Error check the size of the __objc_imageinfo section
llvm-svn: 257841
2016-01-14 23:35:05 +00:00
Pete Cooper 99f3b9494b Check for mismatched arch and OS when linking MachO files.
This patch makes use of the handleLoadedFile hook added in r257814.

That method is used to check the arch and the OS of the files we are linking
against the arch and OS on the context.

The first test to use this ensures that we do not try to combine i386 Mac OS code
with i386 simulator code.

llvm-svn: 257837
2016-01-14 23:25:06 +00:00
Pete Cooper f0c0f3c477 Add File::kind's for all subclasses of File.
This is to enable isa<> support for any files which need it.

It will be used in an upcoming patch to differentiate MachOFile from other implicitly generated files.

Reviewed by Lang Hames.

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

llvm-svn: 257830
2016-01-14 22:55:38 +00:00
Pete Cooper 80c0974c6b Add handleLoadedFile hook to the context.
This is called from the resolver on each file we decide we actually want to use.

Future commits will make use of this to extract useful information from the files and do
error checking against the context.  For example, ensure that files are the same arch as
each other.

Reviewed by Lang Hames.

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

llvm-svn: 257814
2016-01-14 21:53:13 +00:00
Rui Ueyama 489a806965 Update for LLVM function name change.
llvm-svn: 257801
2016-01-14 20:53:50 +00:00
Tom Stellard 3b8cde69aa [old ELF] Remove AMDGPU target
Summary: This is no longer needed now that the new ELF implementation supports AMDGPU.

Reviewers: ruiu, rafael

Subscribers: llvm-commits

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

llvm-svn: 257390
2016-01-11 21:40:40 +00:00
Pete Cooper 03bb2e5931 Always generate the fixup content for unwindFDEToFunction as we no
longer emit it.

llvm-svn: 257100
2016-01-07 21:10:06 +00:00
Pete Cooper ac03979000 Don't emit relocs for the __eh_frame section as they can be implicit.
The __eh_frame section contains relocations which can always be implicitly generated.

This patch tracks whether sections have only implicitly relocations and skips emitting them to the object file if that is the case.

The test case here ensures that this is the case for __eh_frame sections.

Reviewed by Lang Hames.

http://reviews.llvm.org/D15594

llvm-svn: 257099
2016-01-07 21:07:26 +00:00
Pete Cooper 69b18f4703 Set CMake ADDITIONAL_HEADER_DIRS on libraries with headers in /include. NFC.
In a UI such as XCode, it can group the headers for a library with that library.
This is done in the CMakeLists.txt for the library itself by setting the path(s)
as ADDITIONAL_HEADER_DIRS.

LLVM already does this for all of its libraries, so just adding this to lld to
make things easier.  Should be NFC.

llvm-svn: 257002
2016-01-07 00:14:09 +00:00
Pete Cooper f154b678c6 Set the folder for libraries to 'lld libraries'. NFC.
In a UI such as XCode, LLVM source files are in 'libraries' while clang
files are in 'clang libraries'.

This change moves the lld source to 'lld libraries' to make code browsing easier.

It should be NFC as the build itself is still the same, just the structure in a
UI differs.

llvm-svn: 257001
2016-01-07 00:14:04 +00:00
Pete Cooper d53090ac5e Fix MachO arm64 delta32ToGOT reloc encoding in -r.
The fixup content we encode here should be the offset from the
fixup location back to the last nonlocal label.  We were only encoding
the address of the fixup, and not taking in to account the base address
of the atom we are in.

Updated the test case here to have a text section which will come before
the data section where the relocation lives.  .data being at offset 0 had
previously been hiding this bug.

llvm-svn: 256974
2016-01-06 20:53:19 +00:00
Pete Cooper 52db793d33 Improved debugging printing. NFC
llvm-svn: 256805
2016-01-05 01:56:59 +00:00
Pete Cooper bd364ce694 Sort sections in relocatable files.
The final section order in relocatable files was just a side effect
of the atom sorter.  This meant that sections like __data were before
__text because __data has RW permissions and __text RX and RW was less
than RX in our enum.

Final linked images had an actual section/segment sorter.  There was no
reason for the difference, so simplify a bunch of code and just use the
same sorted for everything.

Reviewed by Lang Hames.

http://reviews.llvm.org/D15868

llvm-svn: 256786
2016-01-04 22:29:36 +00:00
Pete Cooper 9942bd025d Fix x86_64 delta*Anon relocs.
The encoded value should be an offset from the fixup location, which
means that it should take in to account the fixup offset in its section.

We weren't subtracting the base address of the atom, which meant that when
we parsed the file again for a round trip, we had 2x the atom address in our
target address.

I've also improved comments for these to try and describe what is going on.

There's no test case right now, as the bug is only exhibited when __data is at
a non-zero address in a -r link.  A commit will soon sort the sections differently
and move __data to after __text.  Then these relocations in
test/mach-o/parse-data-relocs-x86_64.yaml will test for this bug.

llvm-svn: 256779
2016-01-04 21:23:12 +00:00
Pete Cooper 9092eca155 Fix negDelta32 relocatable fixups for arm64 in mach-o.
negDelta32 is only ever implicitly generated as the FDE->CIE reference.
We therefore don't emit a relocation for it in the object file in -r mode.

The value we write in to the FDE location therefore needs to point to the
final target address of the CIE, and not the inAtomAddress as it was currently
doing.

llvm-svn: 255835
2015-12-16 22:50:16 +00:00
Pete Cooper e5fa5a3c29 Add more debugging output to MachO lld. NFC.
In debug builds there's now a dump method on Section and improved
printing of atoms.

llvm-svn: 255826
2015-12-16 22:03:21 +00:00
Pete Cooper 7bf3a85e2b Move parsing of LLVM options to parse() method.
We used to parse the LLVM options in Driver::link.  However, that is
after parse() where we load files.  By moving the LLVM option handling
earlier, we can add DEBUG() to code such as MachONormalizedFileToAtoms.cpp
and have it enabled correctly by '-mllvm --debug'.

llvm-svn: 255819
2015-12-16 20:53:27 +00:00
Pete Cooper 3e8f56565d Added some DEBUG() prints to make it clearer what the mach-o passes are doing. NFC.
We had some DEBUG prints these passes, but add more so that its clear where we are dumping
things, and what state we are in when we do so.

I'll be adding more and more DEBUG printing to try make it easier to observe whats going on
without having to attach a debugger.

llvm-svn: 255805
2015-12-16 19:12:49 +00:00
Lang Hames ac2adce66b [lld][MachO] Recognize __thread_bss sections as zero-fill and set all the
appropriate bits.

This fixes the remaining clang regression test failures when linking clang with
lld on Darwin.

llvm-svn: 255390
2015-12-11 23:25:09 +00:00
Pete Cooper 5cd12580fd Verify that macho-o delta64 relocs have the same offset.
The delta64 relocation is represented as the pair ARM64_RELOC_SUBTRACTOR and ARM64_RELOC_UNSIGNED.

Those should always have the same offset, so this adds a check and tests to ensure this is the case.

Also updated the error printing in this case to shows both relocs when erroring on pair.

llvm-svn: 255274
2015-12-10 18:48:52 +00:00
Lang Hames 201c08f811 [lld][MachO] Always reserve space for the empty string in the mach-o symbol
table.

The first entry in the MachO symbol table is always the empty string: make sure
we reserve space for it, or we will overflow the symbol table by one byte.

No test case - this manifests as an occasional memory error. In the near future
I hope to set up a bot building and runnnig LLD with sanitizers - that should
catch future instances of this issue.

llvm-svn: 255178
2015-12-10 00:12:24 +00:00
Pete Cooper 466d4b006b Don't bypass the GOT for delta32toGOT references.
The gcc_except_tab was generating these references to point to the typeinfo in the data section.

gcc_except_tab also had the DW_EH_PE_indirect flag set which means that at runtime we are going
to dereference this entry as if it is in the GOT.

Reviewed by Nick Kledzik in http://reviews.llvm.org/D15360.

llvm-svn: 255085
2015-12-09 00:46:02 +00:00
Rafael Espindola 9c8904fb38 Rename ld.lld2 to ld.lld since it is the default.
llvm-svn: 253437
2015-11-18 06:11:01 +00:00
Rafael Espindola 7477e99af7 Make ELF2 the default.
With this the only way to get the old elf linker is "-flavor old-elf".

llvm-svn: 253318
2015-11-17 07:19:44 +00:00
Rafael Espindola 97a8695aa1 Rename gnu2 to gnu.
This is the second step in making ELF2 the default.

llvm-svn: 253270
2015-11-16 23:21:55 +00:00
Rafael Espindola 7467461ccc Rename the gnu flavour to gnu old.
This is the first step in making ELF2 the default.

llvm-svn: 253188
2015-11-16 08:54:19 +00:00
Eugene Zelenko 4154794892 Fix Clang-tidy modernize-use-auto warnings, other minor fixes.
Differential revision: http://reviews.llvm.org/D14553

llvm-svn: 252661
2015-11-10 22:37:38 +00:00
Kevin Enderby 35dfc95efe These are the matching changes needed to the lld project for the changes to llvm
in r252192 that changed the Archive and Child interfaces in libObject. These include
Rafael Espindola’s many suggested updates.

llvm-svn: 252193
2015-11-05 19:25:47 +00:00
Eugene Zelenko 6e43b499d2 Fix Clang-tidy modernize-use-override warnings, other minor fixes.
Differential revision: http://reviews.llvm.org/D14310

llvm-svn: 252034
2015-11-04 02:11:57 +00:00
Lang Hames 2ed3bf9527 [lld][MachO] Make sure LC_RPATH command size is a multiple of the pointer size.
llvm-svn: 251637
2015-10-29 16:50:26 +00:00
Lang Hames ac416d42fc [lld][MachO] Use a std::string rather than a StringRef for the section name in
MachODefinedCustomSectionAtom.

The section names for these atoms are initialized from temporaries (e.g.
segName + "/" + sectName), so we can't use StringRef here.

llvm-svn: 251610
2015-10-29 03:57:31 +00:00
Simon Atanasyan 069b2dd66c [Driver] Ignore -G option in both new and old ELF linker
This is optimization option that make sense for MIPS targets. We can
safely ignore it now.

llvm-svn: 251519
2015-10-28 14:50:58 +00:00
Simon Atanasyan 07fe7a943f [Driver] Accept both -m <emulation> and -m<emulation>
GNU linkers accept both variants and at least for MIPS target gcc passes
joined variant of the '-m' option.

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

llvm-svn: 251497
2015-10-28 05:13:12 +00:00
Lang Hames b1b67f4daf [lld][Darwin] Add support for the -sectcreate option.
llvm-svn: 251183
2015-10-24 08:20:51 +00:00
Lang Hames 5e7cfe4e2b [lld][MachO] Prune unused EH frames.
llvm-svn: 251095
2015-10-23 05:39:16 +00:00
Craig Topper f88d22970d Update lld to match llvm r250901. OptTable constructor now takes an ArrayRef. NFC
llvm-svn: 250904
2015-10-21 16:31:56 +00:00
Lang Hames 2483d8f4a7 [lld][MachO] Fix indentation.
llvm-svn: 250863
2015-10-20 21:47:19 +00:00
Lang Hames 650c00be89 [lld][MachO] Fix typo in comment.
llvm-svn: 250861
2015-10-20 21:44:30 +00:00
Rafael Espindola 7d76847da3 Simplify. NFC.
llvm-svn: 249128
2015-10-02 13:23:29 +00:00
Rafael Espindola 98efd89e7e Use ld.lld2 as a argv[0] alias.
The reason for the name is so that we can run

./build/bin/clang -fuse-ld=lld2 test.o -o t

llvm-svn: 249122
2015-10-02 12:57:34 +00:00
Rui Ueyama 43155d0d48 [LLD] Fix Clang-tidy modernize-use-nullptr warnings; other minor cleanups.
Patch from Eugene Zelenko!

llvm-svn: 249111
2015-10-02 00:36:00 +00:00
Lang Hames 9a4c94ec5a [lld][MachO] Fix a think-o to get the twolevel/dynamic_lookup test passing.
llvm-svn: 248736
2015-09-28 20:52:21 +00:00
Lang Hames 5c692009bc [lld][MachO] Initial implementation of -flat_namespace and -undefined.
This is a basic initial implementation of the -flat_namespace and
-undefined options for LLD-darwin. It ignores several subtlties,
but the result is close enough that we can now link LLVM (but not
clang) on Darwin and pass all regression tests.

llvm-svn: 248732
2015-09-28 20:25:14 +00:00
Tom Stellard d0626804fc ELF/AMDGPU: Text section should be called .hsatext
Reviewers: atanasyan, ruiu

Subscribers: llvm-commits

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

llvm-svn: 248621
2015-09-25 21:42:30 +00:00
Rui Ueyama 1392d8b5fe Fix memory leak in FileArchive::find().
Patch from George Rimar!

llvm-svn: 248525
2015-09-24 18:59:26 +00:00
Lang Hames c803442890 [LLD][MachO] Fix a FIXME: Subtract base address from atom address when building
export trie.

llvm-svn: 248217
2015-09-21 22:06:02 +00:00
Simon Atanasyan 92480f9a20 [Mips] Rejects all --hash-style arguments except 'sysv' in case of MIPS target
MIPS ABI supports only --hash-style=sysv variant.

llvm-svn: 247796
2015-09-16 13:36:32 +00:00
Simon Atanasyan 49c67236f1 [Mips] Do not show an error if R_MIPS_GPREL32 relocation has a non-local target
This matches GNU linker behaviour.

llvm-svn: 247795
2015-09-16 13:36:24 +00:00
Rui Ueyama 9071e4a6fa Fix Clang-tidy misc-use-override warnings, other minor fixes.
Patch from Eugene Zelenko!

llvm-svn: 247323
2015-09-10 18:51:36 +00:00
Rui Ueyama 6b0af3c832 Fix -Wcovered-switch-default warnings.
llvm-svn: 246419
2015-08-31 06:46:00 +00:00
Rui Ueyama 692f8683d7 ELF: Fix "not all control paths return a value" warning.
llvm-svn: 246417
2015-08-31 06:32:25 +00:00
Simon Atanasyan e235d45026 [Mips] Support grouping of multiple consecutive relocations in case of N32 and 64-bit MIPS ABIs
llvm-svn: 246337
2015-08-28 21:39:21 +00:00
Simon Atanasyan 9638d7d162 [Mips] Support two more MIPS linking emulation options elf32btsmipn32/elf32ltsmipn32
llvm-svn: 246336
2015-08-28 21:39:13 +00:00
Simon Atanasyan f12120cfe9 [Mips] Make "emulation" option less dependent on the "-target" option.
Now it is possible to have mips-linux-gnu-ld executable and link MIPS 64-bit
little-endian binaries providing -melf64ltsmip command line argument.

llvm-svn: 246335
2015-08-28 21:39:06 +00:00
Simon Atanasyan 6d39140b6e [Mips] Initial support of the MIPS N32 ABI
llvm-svn: 246334
2015-08-28 21:39:00 +00:00
Tom Stellard 8251f978d3 ELF/AMDGPU: Add more misssing: using namespace lld;
Hopefully, this will resolve the remaining windows bot errors.

llvm-svn: 246181
2015-08-27 18:43:12 +00:00
Tom Stellard 39b3d71177 ELF/AMDGPU: Add missing: using namespace lld; to try to fix windows bot
llvm-svn: 246179
2015-08-27 18:27:52 +00:00
Tom Stellard fbbbc01caa ELF/AMDGPU: Remove another unused private member variable
llvm-svn: 246164
2015-08-27 17:11:10 +00:00
Tom Stellard 36c6f6b874 ELF/AMDGPU: Remove unused private member variable
This should fix the one of the failing bots.

llvm-svn: 246160
2015-08-27 16:52:58 +00:00
Tom Stellard ff8dfbd965 ELF/AMDGPU: Attempt to fix windows bots
Broken by r246155.

llvm-svn: 246159
2015-08-27 16:48:46 +00:00
Tom Stellard 15d1fa1bcc ELF: Add AMDGPU ReaderWriter
This is a basic implementation that allows lld to emit binaries
consumable by the HSA runtime.

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

llvm-svn: 246155
2015-08-27 15:55:44 +00:00
Davide Italiano b3c7fb7f24 [LinkerScript] Fix a crash when matching wildcards.
Submitted by:	  zan jyu via llvm-dev

llvm-svn: 245792
2015-08-22 20:36:19 +00:00
Simon Atanasyan 814b705984 [Mips] Use 'or' for move instead of [d]addu in PLT entries
Patch by Simon Dardis.

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

llvm-svn: 245491
2015-08-19 20:20:10 +00:00
Rafael Espindola f0461ba985 Update for llvm api change.
llvm-svn: 244856
2015-08-13 01:07:08 +00:00
Rafael Espindola bdc8f2fb83 Update for llvm api change.
llvm-svn: 244849
2015-08-13 00:31:46 +00:00
David Blaikie a3191ef66b Wdeprecated: Remove unnecessary user-defined dtor that was getting in the way of the default ops (copy construction, assignment, etc)
llvm-svn: 244836
2015-08-12 23:26:58 +00:00
Denis Protivensky 90512d5440 [ELF] Remove TargetLayout::getCustomSegments methods
llvm-svn: 244747
2015-08-12 13:27:27 +00:00
Denis Protivensky 0c8beb1c95 [LinkerScript] Process program header in PHDRS command
Add PT_PHDR segment depending on its availability in linker script's
PHDRS command, fallback if no linker script is given.
Handle FILEHDR, PHDRS and FLAGS attributes of program header.

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

llvm-svn: 244743
2015-08-12 12:31:35 +00:00
Rafael Espindola b61d67cf89 Update for llvm api change.
llvm-svn: 244511
2015-08-10 21:30:13 +00:00
Rafael Espindola d8340dae0c Don't depend on getDotSymtabSec. It is going away.
llvm-svn: 244451
2015-08-10 15:12:17 +00:00
Rui Ueyama 8c484af217 COFF: Remove lld-link2 alias.
llvm-svn: 244358
2015-08-07 21:02:36 +00:00
Rafael Espindola b6aa962e42 Avoid using getDotDynSymSec in lld. It is going away.
llvm-svn: 244350
2015-08-07 20:01:24 +00:00
Rafael Espindola 1a9344fa26 Use already available symbol tables. NFC.
llvm-svn: 244336
2015-08-07 17:16:28 +00:00
Tom Stellard 01da42d8db ELF: Correctly identify SHT_NOTE sections with !SHF_ALLOC as type*Note
Subscribers: llvm-commits

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

llvm-svn: 244317
2015-08-07 14:36:04 +00:00
Rui Ueyama 251b0e268b COFF: Remove the old COFF linker and make link an alias to link2.
It's time to remove old COFF linker because the new one is now complete.

llvm-svn: 244226
2015-08-06 16:19:35 +00:00
Rafael Espindola b835ae8e4a Port the error functions from ELF to COFF.
This has a few advantages

* Less C++ code (about 300 lines less).
* Less machine code (about 14 KB of text on a linux x86_64 build).
* It is more debugger friendly. Just set a breakpoint on the exit function and
  you get the complete lld stack trace of when the error was found.
* It is a more robust API. The errors are handled early and we don't get a
  std::error_code hot potato being passed around.
* In most cases the error function in a better position to print diagnostics
  (it has more context).

llvm-svn: 244215
2015-08-06 14:58:50 +00:00
Simon Atanasyan 7a400d9af4 [Mips] Implement definition of the DT_MIPS_RLD_MAP_REL dynamic tag
llvm-svn: 243835
2015-08-01 14:53:49 +00:00
Simon Atanasyan 98a857140b [Mips] Implement definition of DT_MIPS_RLD_MAP dynamic tag, .rld_map section, and __RLD_MAP symbol
llvm-svn: 243626
2015-07-30 07:45:55 +00:00
Simon Atanasyan 9191a84392 [Mips] Define _DYNAMIC_LINKING symbol if output is a is dynamically linked executable file
llvm-svn: 243211
2015-07-25 10:18:52 +00:00
Simon Atanasyan 8e24577100 [Mips] Remove redundant separate functions to calculate relocations. Do
that inline.

No functional changes.

llvm-svn: 243210
2015-07-25 10:18:44 +00:00
Simon Atanasyan 4504791890 [Mips] Remove duplicated code by joining the same functions
llvm-svn: 243209
2015-07-25 10:18:39 +00:00
Simon Atanasyan 3b6ea7ab4a [Mips] Do not sign-extend addends read from RELA relocation records
llvm-svn: 243208
2015-07-25 10:18:33 +00:00
Michael J. Spencer 84487f1174 [ELF2] Add a new ELF linker based on the new PE/COFF linker.
Differential Revision: http://reviews.llvm.org/D11188

llvm-svn: 243161
2015-07-24 21:03:07 +00:00
Rui Ueyama 8abca7e729 Fix -Wextra-semi.
Patch from Eugene.Zelenko!

llvm-svn: 243060
2015-07-23 23:03:55 +00:00
Rafael Espindola 5871bf30ac Use the getSymbol with an explicit symbol table. NFC.
llvm-svn: 243014
2015-07-23 13:41:25 +00:00
Denis Protivensky f84acb959b [LinkerScript] Fix case when setting custom NONE segment
llvm-svn: 243006
2015-07-23 11:46:59 +00:00
Denis Protivensky cdc1246750 [ELF] Apply segments from linker scripts
Put sections to segments according to linker scripts if available.
Rework the code of TargetLayout::assignSectionsToSegments so it operates
on the given list of segments, which can be either read from linker scripts
or constructed as before.
Handle NONE segments defined in linker scripts by putting corresponding sections
to PT_NULL segment.
Consider flags set for segments through linker scripts.

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

llvm-svn: 243002
2015-07-23 10:34:30 +00:00
Simon Atanasyan b6d60a69c0 [ELF] Protect write access to the ELFLinkingContext::_cidentSections by a mutex
The _cidentSections container is filled during files parsing so we need to
serialize a concurrent access to it.

llvm-svn: 242885
2015-07-22 10:32:19 +00:00
Rafael Espindola 1cb8a19bcb Don't assume ELFFile iterates over the program headers.
It will stop doing so shortly.

llvm-svn: 242832
2015-07-21 20:46:21 +00:00
Rafael Espindola 5f95fa31b3 Drop last use of getDynamicSymbolName.
llvm-svn: 242820
2015-07-21 18:15:32 +00:00
Rafael Espindola 16154afb06 Keep track of which string table is associated with a symbol table.
This removes the last uses of getStaticSymbolName in lld.

llvm-svn: 242816
2015-07-21 18:00:39 +00:00
Simon Atanasyan b1600f2eee [Mips] Fix addend writing for R_MIPS_REL32 relocation
llvm-svn: 242760
2015-07-21 05:54:30 +00:00
Simon Atanasyan f9db71eaec [Mips] Handle R_MIPS_JALR relocation to omptimize jalr/jr instructions
llvm-svn: 242759
2015-07-21 05:54:22 +00:00
Rafael Espindola d285d3fbb7 Update for llvm api change.
llvm-svn: 242701
2015-07-20 20:08:04 +00:00
Rafael Espindola 9170a17377 Update for llvm api change.
llvm-svn: 242216
2015-07-14 22:19:09 +00:00
Adhemerval Zanella 4d0d1babfc [ELF/AArch64] Fix export TLS dynamic symbol
This patch fixes the TLS dynamic variable exportation from .got.plt segments,
created by General-dynamic relocations (TLSDESC).  Current code only export
symbols in dynamic table from .got sections.

llvm-svn: 242142
2015-07-14 13:25:32 +00:00
Michael J. Spencer bae540e945 Revert ELF port. Posting to mailing list.
llvm-svn: 242118
2015-07-14 04:49:48 +00:00
Rafael Auler 2c4af3ead7 [LinkerScript] Don't create unnecessarily large segments
When using a linker script expression to change the address of a section, even
if the new address is more than a page of distance from the old address, lld
may put everything in the same segment, forcing it to be unnecessarily large.
This patch changes the logic in Segment::assignVirtualAddress() and
Segment::assignFileOffsets() to allow the segment to be sliced into two or more
if it detects a linker script expression that changes a section address.

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

llvm-svn: 242096
2015-07-14 00:34:43 +00:00
Rafael Auler a4917f74eb [LinkerScript] Fix bug in Segment::assignVirtualAddress()
When calculating the start address and size of a segment, lld mistakenly
attributed the start address of the last segment slice to the whole segment
when it should consider the start address of the first slice. In this case, in a
multi-slice segment, Segment::assignVirtualAddress() will return a wrong
segment start address to TargetLayout::assignVirtualAddress(). The effect of
this miscalculation is to allocate some program headers in unnecessarily far
away addresses. This commit fixes this.

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

llvm-svn: 242089
2015-07-13 23:52:58 +00:00
Michael J. Spencer 8a4145411f Initial ELF port.
This is a direct port of the new PE/COFF linker to ELF.

It can take a single object file and generate a valid executable that executes at the first byte in the text section.

llvm-svn: 242088
2015-07-13 23:48:06 +00:00
Simon Atanasyan b34a080701 [Mips] Support MIPS big-endian 32/64-bits targets
llvm-svn: 242014
2015-07-13 09:11:35 +00:00
Nico Weber d08eca0181 elf: Make error output from AtomSection<ELFT>::write() deterministic.
The function uses parallel_for() and then writes error messages from the
parallel loop's body.  This produces nondetermistic error messages.  Instead,
copy error messages to a vector and sort it by the atom's file offsets before
printing all error messages after the parallel_for().  This results in a few
string copies, but only in the error case.  (And passing tests seem more
important than performance.)

This makes tests elf/AArch64/rel-prel16-overflow.test and
elf/AArch64/rel-prel32-overflow.test pass on Windows: Both tests check that
atom error messages are emitted in a certain order, and on Windows they
happened to be emitted in a different order before this patch.

llvm-svn: 241988
2015-07-12 04:45:35 +00:00
Rafael Espindola dbb40ab8b7 Update for upcoming llvm change.
llvm-svn: 241746
2015-07-08 22:14:36 +00:00
Davide Italiano 5a2acd1e1e Fix undefined behaviour exposed by the new -Wshift-negative-value warning.
llvm-svn: 241530
2015-07-07 00:02:59 +00:00
Adhemerval Zanella c0ad64543b [ELF/AArch64] Set correct loader name in linking context
This patch reimplements ELFLinkingContext::getDefaultInterpreter for aarch64
with correct loader name. It is required to exclude the loader from DT_NEEDED
in shared library creation.

llvm-svn: 241371
2015-07-03 21:24:36 +00:00
Adhemerval Zanella fdb4d6346a [ELF/AArch64] Set correct loader name in linking context
This patch reimplements ELFLinkingContext::getDefaultInterpreter for aarch64
with correct loader name.  It is required to exclude the loader from DT_NEEDED
in shared library creation.

llvm-svn: 241370
2015-07-03 21:21:39 +00:00
Rafael Espindola ec57b8b9f8 Use getDynamicSymbolName/getStaticSymbolName instead of a constant argument.
llvm-svn: 241346
2015-07-03 12:50:54 +00:00
Simon Atanasyan 47a2eafd5c [Mips] Factor out symbol type checking (PIC/non-PIC) into the separate function
No functional changes.

llvm-svn: 241342
2015-07-03 11:36:55 +00:00
Simon Atanasyan a87c17a201 [ELF] Define __start_XXX/__stop_XXX symbols where XXX is a section name
This is GNU ELF linker extension used particularly by LibC code.
If input object files contain section named XXX, and the XXX is a valid C
identifier, and there are undefined or weak symbols __start_XXX/__stop_XXX,
linker should define __start_XXX/__stop_XXX symbols point to the begin/end
of the XXX section correspondingly.

For example, without support of this extension statically linked executables
for X86_64 and Mips (maybe other) targets do not flush IO buffers at the end
of executing.

llvm-svn: 241341
2015-07-03 11:25:37 +00:00
Rafael Espindola cd55286893 Update for llvm changes.
llvm-svn: 241298
2015-07-02 20:55:28 +00:00
Simon Atanasyan b28f504226 [ELF] Remove dead code. NFC
llvm-svn: 241274
2015-07-02 15:04:08 +00:00
Simon Atanasyan 0d38933235 [ELF] Make OutputSection::memSize `const` member function. NFC
llvm-svn: 241194
2015-07-01 21:44:55 +00:00
Adhemerval Zanella dbd75b7fa0 [ELF/AArch64] Initial General-dynamic TLS support
This patch adds initial general-dynamic TLS support for AArch64.  Currently
no optimization is done to realx for more performance-wise models (initial-exec
or local-exec).  This patch also only currently handles correctly executable
generation, although priliminary DSO support through PLT specific creation
is also added.

With this change clang/llvm bootstrap with lld is possible in static configuration
(some DSO creation fails due missing Linker script support, not AArch64 specific),
although make check also shows some issues.

llvm-svn: 241192
2015-07-01 21:35:39 +00:00
Rafael Espindola a5ee9fdea2 Update for llvm api change.
llvm-svn: 241157
2015-07-01 12:56:33 +00:00
Rafael Espindola 1acc30e970 Use copy init instead of direct init.
llvm-svn: 241089
2015-06-30 18:04:46 +00:00
Rafael Espindola 29efdd4a21 Update for llvm change.
llvm-svn: 241075
2015-06-30 15:34:00 +00:00
Rafael Espindola bff864a596 Update for llvm api change.
llvm-svn: 240997
2015-06-29 21:26:07 +00:00
Rafael Espindola fdeb19ff33 Update for llvm api change.
llvm-svn: 240951
2015-06-29 14:39:30 +00:00
Rafael Espindola 4d24127ae0 Update for llvm change.
llvm-svn: 240940
2015-06-29 12:38:35 +00:00
Rafael Espindola bb50727e94 Update for llvm changes.
llvm-svn: 240781
2015-06-26 13:19:38 +00:00
Simon Atanasyan 253125af03 [Mips] Reject R_MIPS_CALL16 against local symbols
llvm-svn: 240765
2015-06-26 07:25:20 +00:00
Simon Atanasyan 52db6aefcc [Mips] Use helper functions to determine relocations purpose
That allows to remove duplicated long switch/case statements.

No functional changes.

llvm-svn: 240764
2015-06-26 07:25:12 +00:00
Simon Atanasyan b7bcff8796 [Mips] Create LA25 stubs for all branch relocations
llvm-svn: 240763
2015-06-26 07:25:06 +00:00
Adhemerval Zanella 3ebea27d66 [ELF] Fix .init_array initialization
Some compilers may not add the section symbol in '.symtab' for the
.init_array and 'ldd' just ignore it.  It results in global constructor
not being called in final executable.

This patch add both '.init_array' and '.fini_array' to be added in
Atom graph generation even when the section contains no symbol.  An
already existing testcase is modified to check for such scenario.

The issue fixes the llvm test-suite regressions for both Single
and MultiSource files.

llvm-svn: 240570
2015-06-24 19:26:00 +00:00
Lang Hames 49047039b0 [lld] Add MachO thread-local storage support.
This allows LLD to correctly link MachO objects that use thread-local storage.

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

llvm-svn: 240454
2015-06-23 20:35:31 +00:00
Benjamin Kramer cfacc9d3e6 [MachO] Initialize all fields of NormalizedFile.
The ObjectFileYAML.roundTrip serializes a default-constructed
NormalizedFile to YAML, triggering uninitialized memory reads.

While there use in-class member initializers.

llvm-svn: 240446
2015-06-23 19:55:04 +00:00
Benjamin Kramer 44b0723069 Add missing dependencies for the CMake shared lld build.
llvm-svn: 240445
2015-06-23 19:54:57 +00:00
David Blaikie 6521ed964b Update for LLVM API change to return by InputArgList directly (rather than by pointer) from ParseArgs
llvm-svn: 240347
2015-06-22 22:06:52 +00:00
David Blaikie 008181933d Fix missed formatting in prior commit (mostly 80 cols violation and some whitespace around *)
llvm-svn: 240346
2015-06-22 22:06:48 +00:00
Simon Atanasyan 356d7c52b6 [Mips] Support R_MICROMIPS_HI0_LO16 relocation handling
llvm-svn: 240268
2015-06-22 09:27:05 +00:00
Simon Atanasyan f44f854af3 [Mips] Support R_MICROMIPS_LITERAL relocation handling
llvm-svn: 240267
2015-06-22 09:26:57 +00:00
Simon Atanasyan 692e792575 [Mips] Support R_MIPS_LITERAL relocation handling
llvm-svn: 240266
2015-06-22 09:26:48 +00:00
Simon Atanasyan ca0fe2f4a4 [Mips] Support R_MICROMIPS_SUB relocation handling
llvm-svn: 240265
2015-06-22 09:26:41 +00:00
Simon Atanasyan 1af72b898c [Mips] Reject R_MIPS_GPREL32 against external symbols
llvm-svn: 240264
2015-06-22 09:26:33 +00:00
Simon Atanasyan b5d26b1433 [Mips] Reject position-dependent relocations in case of shared library linking
llvm-svn: 240262
2015-06-22 09:26:20 +00:00
Simon Atanasyan 46d97f246b [Mips] Support R_MICROMIPS_HIGHER / R_MICROMIPS_HIGHEST relocations handling
llvm-svn: 240260
2015-06-22 09:26:05 +00:00
Simon Atanasyan e55110454d [Mips] Support R_MIPS_HIGHER / R_MIPS_HIGHEST relocations handling
llvm-svn: 240259
2015-06-22 09:25:57 +00:00
David Blaikie b2b1c7c3e1 ArrayRef-ify Driver::parse and related functions.
llvm-svn: 240236
2015-06-21 06:32:10 +00:00
David Blaikie 8da889f1a5 ArrayRef-ify ParseArgs
llvm-svn: 240235
2015-06-21 06:32:04 +00:00
David Blaikie dccc8e2cc1 Fix no-asserts build failure due to unused variable, and cleanup some unique_ptr usage while I'm here
llvm-svn: 240169
2015-06-19 19:55:25 +00:00
David Blaikie 25ddcb4c27 Simplify Pass::perform to take a SimpleFile& instead of unique_ptr<SimpleFile>&
None of the implementations replace the SimpleFile with some other file,
they just modify the SimpleFile in-place, so a direct reference to the
file is sufficient.

llvm-svn: 240167
2015-06-19 19:43:43 +00:00
Lang Hames b09c2c6edb [lld] Allow LLD passes to return error codes.
llvm-svn: 240147
2015-06-19 17:51:46 +00:00
Simon Atanasyan 13cda3edf6 [Mips] Write inline some more relocation calculations
No functional changes.

llvm-svn: 239961
2015-06-17 22:28:16 +00:00
Simon Atanasyan f8b082a6aa [Mips] Support R_MICROMIPS_GPREL16 / R_MICROMIPS_GPREL7_S2 relocations handling
llvm-svn: 239960
2015-06-17 22:27:54 +00:00
Simon Atanasyan 17478c5804 [Mips] Support R_MIPS_16 relocation handling
llvm-svn: 239959
2015-06-17 22:27:39 +00:00
Simon Atanasyan 6f1e05f388 [Mips] Do not use functions to calculate trivial relocations
No functional changes.

llvm-svn: 239957
2015-06-17 22:27:27 +00:00
Davide Italiano 6cac62797f [ELF] Now that there's an API for ELF symbol types in LLVM, use it.
Common symbols will be handled in a separate patch because it seems
Hexagon redefines the notion of common symbol, which I'm not (yet)
very familiar with.

llvm-svn: 239951
2015-06-17 21:50:51 +00:00
Adhemerval Zanella b19f5cfee6 [ELF/x86_64] Fix initial-exec TLS access
Current approach for initial-exec in ELF/x86_64 is to create a GOT entry
and change the relocation to R_X86_64_PC32 to be handled as a GOT offfset.
However there are two issues with this approach: 1. the R_X86_64_PC32 is
not really required since the GOT relocation will be handle dynamically and
2. the TLS symbols are not being exported externally and then correct
realocation are not being applied.

This patch fixes the R_X86_64_GOTTPOFF handling by just emitting a
R_X86_64_TPOFF64 dynamically one; it also sets R_X86_64_TPOFF64 to be
handled by runtime one.  For second part, the patches uses a similar
strategy used for aarch64, by reimplementing buildDynamicSymbolTable
from X86_64ExecutableWriter and adding the TLS symbols in the dynamic
symbol table.

Some tests had to be adjusted due the now missing R_X86_64_PC32 relocation.
With this test the simple testcase:

* t1.c:

__thread int t0;
__thread int t1;
__thread int t2;
__thread int t3;

* t0.c:

extern __thread int t0;
extern __thread int t1;
extern __thread int t2;
extern __thread int t3;

__thread int t4;
__thread int t5;
__thread int t6;
__thread int t7;

int main ()
{
  t0 = 1;
  t1 = 2;
  t2 = 3;
  t3 = 4;

  t4 = 5;
  t5 = 6;
  t6 = 7;
  t7 = 8;

  printf ("%i %i %i %i\n", t0, t1, t2, t3);
  printf ("%i %i %i %i\n", t4, t5, t6, t7);

  return 0;
}

Shows correct output for x86_64.

llvm-svn: 239908
2015-06-17 14:00:12 +00:00
Adhemerval Zanella 9c5831f3de [ELF] Fix wrong TBSS size
This patch fixes the wrong .tbss segment size generated for cases where
multiple modules have non initialized threads variables.  For instance:

* t0.c

__thread int x0;
__thread int x1;
__thread int x2;

extern __thread int e0;
extern __thread int e1;
extern __thread int e2;
extern __thread int e3;

int foo0 ()
{
  return x0;
}

int main ()
{
  return x0;
}

* t1.c

__thread int e0;
__thread int e1;
__thread int e2;
__thread int e3;


lld is generating (for aarch64):

  [14] .tbss             NOBITS           0000000000401000  00001000
       0000000000000010  0000000000000000 WAT       0     0     4

Where is just taking in consideration the largest tbss segment, not all
from all objects.  ld generates a correct output:

  [17] .tbss             NOBITS           0000000000410dec  00000dec
       000000000000001c  0000000000000000 WAT       0     0     4

This issue is at 'lib/ReaderWriter/ELF/SegmentChunks.cpp' where
Segment<ELFT>::assignVirtualAddress is setting wrong slice values, not taking care
of although tbss segments file size does noy play role in other segment virtual
address placement, its size should still be considered.

llvm-svn: 239906
2015-06-17 13:46:07 +00:00
Denis Protivensky 1aaf736d89 [LinkerScript] Add matching of output sections to segments
Add method to query segments for specified output section name.
Return error if the section is assigned to unknown segment.
Check matching of sections to segments during layout on the subject of correctness.
NOTE: no actual functionality of using custom segments is implemented.

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

llvm-svn: 239719
2015-06-15 08:00:51 +00:00
Rafael Espindola a0b4c565fd Don't use std::errc.
As noted on Errc.h:

// * std::errc is just marked with is_error_condition_enum. This means that
//   common patters like AnErrorCode == errc::no_such_file_or_directory take
//   4 virtual calls instead of two comparisons.

And on some libstdc++ those virtual functions conclude that

------------------------
int main() {
  std::error_code foo = std::make_error_code(std::errc::no_such_file_or_directory);
  return foo == std::errc::no_such_file_or_directory;
}
-------------------------

should exit with 0.

llvm-svn: 239685
2015-06-13 17:23:15 +00:00
Simon Atanasyan 6df6c75b61 [Mips] Support R_MIPS_PC16 relocation handling
llvm-svn: 239677
2015-06-13 14:48:14 +00:00
Simon Atanasyan 3d13c7dc67 [Mips] Use standard relocations R_MIPS_HI16/LO16 instead of custom variants
No functional changes.

llvm-svn: 239676
2015-06-13 14:48:04 +00:00
Rafael Espindola 9bd82e9952 Update for llvm api change.
llvm-svn: 239671
2015-06-13 12:50:13 +00:00
Simon Atanasyan 5f54812cb0 [Mips] Handle TLS relocations in -static linking mode
llvm-svn: 239615
2015-06-12 16:13:14 +00:00
Simon Atanasyan d5296b206b [Mips] Define _gpxxx symbols in both static/dynamic linking modes
llvm-svn: 239614
2015-06-12 16:13:00 +00:00
Simon Atanasyan 01cde9cf5a [Mips] Setup EI_ABIVERSION flag
- Set EI_ABIVERSION to '1' in case of non-PIC executable.
- Set EI_ABIVERSION to '3' in case of using FP64/FP64A floating point ABI.

llvm-svn: 239613
2015-06-12 16:12:50 +00:00
Simon Atanasyan 253fd15977 [Mips] Factor out some bit manipulation code into separate routines
No functional changes.

llvm-svn: 239226
2015-06-06 17:26:35 +00:00
Simon Atanasyan c859644f67 [Mips] Check symbol alignment for some MIPS relocations.
llvm-svn: 239225
2015-06-06 17:26:28 +00:00
Simon Atanasyan 439af8550e [Mips] Perform an overflow checking for relocations results
llvm-svn: 239224
2015-06-06 17:26:18 +00:00
Simon Atanasyan 26b1c4584d [Mips] Rearrange relocation related cases in the `switch` operator
No functional changes.

llvm-svn: 239223
2015-06-06 17:26:09 +00:00
Simon Atanasyan e801f43655 [Mips] Use signed/unsigned types in relocation calculations consistently
No functional changes.

llvm-svn: 239222
2015-06-06 17:26:04 +00:00
Simon Atanasyan 6d19105c1d [Mips] Handle all grouped relocations in a uniform way
No functional changes.

llvm-svn: 239221
2015-06-06 17:25:58 +00:00
Adhemerval Zanella c694b40590 [ELF/AArch64] Fix build issue on MSVC
This patch fixes a build issue from r238981.

llvm-svn: 238986
2015-06-03 22:47:41 +00:00
Adhemerval Zanella 9f0c63bfdf [ELF/AArch64] Fix TLS initial executable relocation
This patch fixes the TLS initial executable for AArch64.  Current
implementation have two issues: 1. does not generate dynamic
R_AARCH64_TLS_TPREL64 relocation for the external module symbols,
and 2. does not export the TLS initial executable symbol in dynamic
symbol table.

The fix follows the MIPS strategy to add a arch-specific GOTSection
class to keep track of TLS symbols required to be place in dynamic
symbol table. It also overrides the buildDynamicSymbolTable for
ExecutableWrite class to add the symbols.

It also adds some refactoring on AArch64RelocationPass.cpp based on ARM
backend.

llvm-svn: 238981
2015-06-03 21:44:03 +00:00
Adhemerval Zanella 4bcc13d988 [ELF/AArch64] Fix correct TCB aligment calculation
This patch fixes the TLS local relocations alignment done by @238258.
As pointed out, the TLS size should not be considered, but rather the
TCB size based on maximum output segment alignment.  Although it has
not shown in the TLS simple cases for test-suite, more comprehensible
tests with more local TLS variable showed wrong relocations values
being generated.

The local TLS testcase is expanded to add more tls variable (both
exported and static) initialized or not.

llvm-svn: 238960
2015-06-03 20:39:30 +00:00
Denis Protivensky dad8aa8241 [Mips] Fix enumeral vs. non-enumeral warning in ternary. NFC
That's a weird gcc's complain.

llvm-svn: 238812
2015-06-02 09:22:38 +00:00
Simon Atanasyan faa8bfdd1a [Mips] Add a couple of MipsAbiInfoHandler functions to check linked code type
No functional changes.

llvm-svn: 238689
2015-05-31 20:37:22 +00:00
Simon Atanasyan 2944e4a43d [Mips] Do not put the .reginfo section into the separate segment
The .reginfo should not belong to the separate segment if there is
a .MIPS.abiflags section.

llvm-svn: 238688
2015-05-31 20:37:13 +00:00
Simon Atanasyan c140b41c39 [Mips] Sort segments so PT_MIPS_ABIFLAGS goes right after the PT_INTERP
llvm-svn: 238687
2015-05-31 20:36:58 +00:00
Simon Atanasyan c90c425735 [Mips] Reading, merging and writing .MIPS.abiflags section
http://dmz-portal.mips.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking

llvm-svn: 238686
2015-05-31 20:36:43 +00:00
Simon Atanasyan 3eec407a53 [Mips] Delete MipsReginfo structure. Use the Elf_Mips_RegInfo instead.
llvm-svn: 238685
2015-05-31 20:36:21 +00:00
Simon Atanasyan 70e21bc83d [Mips] Collect all ABI related info in the single MipsAbiInfoHandler class
New MipsAbiInfoHandler merges and hold both ELF header flags
and registries usage masks. In the future commits it will manage some
additional information.

llvm-svn: 238684
2015-05-31 20:36:11 +00:00
Rui Ueyama 411c636081 COFF: Add a new PE/COFF port.
This is an initial patch for a section-based COFF linker.

The patch has 2300 lines of code including comments and blank lines.
Before diving into details, you want to start from reading README
because it should give you an overview of the design.

All important things are written in the README file, so I write
summary here.

- The linker is already able to self-link on Windows.

- It's significantly faster than the existing implementation.
  The existing one takes 5 seconds to link LLD on my machine,
  while the new one only takes 1.2 seconds, even though the new
  one is not multi-threaded yet. (And a proof-of-concept multi-
  threaded version was able to link it in 0.5 seconds.)

- It uses much less memory (250MB vs. 2GB virtual memory space
  to self-host).

- IMHO the new code is much simpler and easier to read than
  the existing PE/COFF port.

http://reviews.llvm.org/D10036

llvm-svn: 238458
2015-05-28 19:09:30 +00:00
Michael J. Spencer 42a738198b Fix unused variable warnings.
llvm-svn: 238384
2015-05-28 00:29:56 +00:00
Michael J. Spencer cc0554d057 Add PHDR and FILL parsing.
llvm-svn: 238383
2015-05-28 00:14:58 +00:00
Simon Atanasyan 06eccbea9d [Mips] Move member function definitions to cpp files
No functional changes.

llvm-svn: 238310
2015-05-27 11:56:15 +00:00
Simon Atanasyan bb399f3d57 [ELF][Mips] Do not merge ELF flags in the `isCompatible` routine
We do not need to merge ELF flags from DSO. But `isCompatible` is called
for all input files. So this change move ELF flags merging into the
MipsELFFile class.

llvm-svn: 238304
2015-05-27 08:45:31 +00:00
Simon Atanasyan 256f2cadfe [Mips] Factor out look up of Elf_Mips_RegInfo structure into the separate function
No functional changes.

llvm-svn: 238303
2015-05-27 08:45:21 +00:00
Adhemerval Zanella f3c1c065aa [ELF/AArch64] Fix local TLS relocations
This patch fixes the R_AARCH64_TLSLE_ADD_TPREL_HI12 and R_AARCH64_TLSLE_ADD_TPREL_LO12_NC
handling by using the correct offset by using the target layout along with
aarch64 alignments requirements.

It fixes the TLS test-suite SingleSource failures for aarch64:

* SingleSource/UnitTests/Threads/2010-12-08-tls.execution_time
* SingleSource/UnitTests/Threads/tls.execution_time

llvm-svn: 238258
2015-05-26 21:49:39 +00:00
Denis Protivensky 499292dede [ARM] Fix enum type cast in switch
It caused warning in clang assuming the default
branch would never be reached with the given
switch key type.

llvm-svn: 238194
2015-05-26 11:13:09 +00:00
Denis Protivensky 02fc0b1d64 [ARM] Move out .ARM.exidx related things to ARM backend
llvm-svn: 238191
2015-05-26 10:26:15 +00:00
Simon Atanasyan b48abf5dac [Mips] Use structures declared in the llvm/Object/ELFTypes.h
No functional changes.

llvm-svn: 238189
2015-05-26 08:48:33 +00:00
Simon Atanasyan e62aa7457f [Mips] Add Elf_Mips_Options::getRegInfoDesc() function to retrieve an ODK_REGINFO descriptor
No functional changes.

llvm-svn: 238176
2015-05-26 06:05:07 +00:00
Simon Atanasyan e09faec16e [Mips] Make the code shorter - use LLVM_ELF_IMPORT_TYPES_ELFT macro
No functional changes.

llvm-svn: 238175
2015-05-26 06:05:01 +00:00
Davide Italiano 683703ea6d [ELF] Add support for -z origin/now options.
Differential Revision:	http://reviews.llvm.org/D9963

llvm-svn: 238169
2015-05-26 01:57:32 +00:00
Simon Atanasyan 0b22359858 [ELF] Fix lld when no unique sections is used
Original patch of Shankar Easwaran with additional test case.
The yaml2obj does not allow to create an object file with non-unique
sections names so the fix uses a binary input object file in the test
case.

llvm-svn: 238115
2015-05-24 16:19:27 +00:00
Benjamin Kramer ebcc0dcad1 Remove redundant std::move on functions that return a unique_ptr.
llvm-svn: 238034
2015-05-22 17:52:04 +00:00
Benjamin Kramer 91d8cfd698 [ELF] Remove redundant unique_ptr moves found by -Wpessimizing-move.
llvm-svn: 238030
2015-05-22 16:01:21 +00:00
Benjamin Kramer fc99f3d43f [ELF] Fix shared CMake build.
llvm-svn: 238029
2015-05-22 16:01:12 +00:00
Denis Protivensky f2c22f4ff8 [ARM] report_fatal_error for not implemented functionality
llvm-svn: 238017
2015-05-22 12:39:05 +00:00
Denis Protivensky 575f7d4f1c [ARM] Ability to add GOT and PLTGOT entries for same symbol
These two serve different purpose:
PLTGOT entries are (usually) lazily resolved and serve as trampolines
to correctly call dynamically linked functions. They often have
R_*_JUMP_SLOT dynamic relocation type used.
Simple GOT entries hold other things, one of them may be
R_*_GLOB_DAT to correctly reference global and static data. This
is also used to hold dynamically linked function's address.

To properly handle cases when shared object's function is called
and at the same time its address is taken, we need to be able to have
both GOT and PLTGOT entries bearing different dynamic relocation types
for the same symbol.

llvm-svn: 238015
2015-05-22 11:23:39 +00:00
Denis Protivensky 214122cffc [ARM] Implement R_ARM_GLOB_DAT for GOT entries
This is used when referencing global or static data in shared
objects. This is also used when function's address is taken and
function call is made indirectly.

llvm-svn: 238014
2015-05-22 11:00:31 +00:00
Lang Hames ff4b13c538 [lld] Make the MachO -stack_size default '0', add a test case.
Addresses some review comments for r237841.

llvm-svn: 237979
2015-05-22 00:25:34 +00:00
Davide Italiano 339191fcfa [ELF] Simplify dynamic table entry creation.
Differential Revision:	http://reviews.llvm.org/D9921
Reviewed by:  atanasyan

llvm-svn: 237973
2015-05-21 23:44:19 +00:00
Denis Protivensky af1c9dd513 [ARM] Add dynamic symbols to the dynamic library writer
llvm-svn: 237898
2015-05-21 12:52:00 +00:00
Denis Protivensky eb273b6b28 [ARM] Remove useless file with writer's instantiation stub
llvm-svn: 237896
2015-05-21 12:31:15 +00:00
Denis Protivensky db2b179b1e [ARM] Remove unused field in executable writer
llvm-svn: 237892
2015-05-21 11:50:54 +00:00
Denis Protivensky ad52e44e98 [ARM] Move out common Writer functionality to ARMELFWriter
llvm-svn: 237891
2015-05-21 11:16:40 +00:00
Denis Protivensky 30e40be080 [ELF] Move start/end atom method assignment to OutputELFWriter. NFC
llvm-svn: 237886
2015-05-21 10:11:27 +00:00
Denis Protivensky e6651618a8 [ARM] Remove unused fields in dynamic library writer
llvm-svn: 237883
2015-05-21 09:52:21 +00:00
Denis Protivensky 2db1a03b07 [ARM] Add skeleton implementation of DSO linking
llvm-svn: 237881
2015-05-21 09:28:25 +00:00
Lang Hames 65a64c9c29 [LLD] Add support for the -stack_size option to Darwin ld.
llvm-svn: 237841
2015-05-20 22:10:50 +00:00
Denis Protivensky 56b12d75bf [ARM] Add needed symbols during dynamic executable linking
These include _GLOBAL_OFFSET_TABLE_ and _DYNAMIC.

llvm-svn: 237791
2015-05-20 13:39:33 +00:00
Lang Hames 3d2911f5cd [LLD] Make sure MachO FDEs read their augmentation data strings from the right
CIE, not just the most recently encountered one.

llvm-svn: 237491
2015-05-16 00:08:02 +00:00
Lang Hames f7c163c986 [LLD] Properly relocate the LSDA field of MachO eh-frames.
Previously the LSDA field was not being relocated during linking, leading to
failures for some EH tests.

llvm-svn: 237222
2015-05-13 00:44:47 +00:00
Lang Hames 6483c00079 [LLD] Add support for MachO ripRel32MinusNAnon relocations.
llvm-svn: 237219
2015-05-13 00:29:43 +00:00
Lang Hames 9bbc3653c5 [LLD] Add a mutex to prevent concurrent modification of the dylib maps in
MachOLinkingContext.

llvm-svn: 237217
2015-05-13 00:17:08 +00:00
Davide Italiano d3142ec82b [ARM] Use the correct variable name and unbreak buildbot.
llvm-svn: 236880
2015-05-08 16:49:18 +00:00
Leny Kholodov bde4144338 [ARM] Generation of .ARM.exidx/.ARM.extab sections
This patch provides generation of .ARM.exidx & .ARM.extab sections which are
used for unwinding. The patch adds new content type typeARMExidx for atoms from
.ARM.exidx section and integration of atoms with such type to the ELF
ReaderWriter. exidx.test has been added with checking of contents of .ARM.exidx
section and .ARM.extab section.

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

llvm-svn: 236873
2015-05-08 16:04:11 +00:00
Denis Protivensky 679c2c3639 [ARM] Check overflow of R_ARM_THM_JUMP11
llvm-svn: 236842
2015-05-08 12:45:11 +00:00
Denis Protivensky 73e927885c [ARM] Check overflow of R_ARM_CALL/JUMP24
llvm-svn: 236841
2015-05-08 12:36:40 +00:00
Denis Protivensky a0cffffcfa [ARM] Check overflow of R_ARM_THM_CALL/JUMP24
llvm-svn: 236839
2015-05-08 12:34:43 +00:00
Denis Protivensky 1a3bd31e52 [ARM] Check overflow of R_ARM_PREL31
llvm-svn: 236729
2015-05-07 14:05:30 +00:00
Denis Protivensky cf4e031b36 [ARM] llvm_unreachable => make_dynamic_error in R_ARM_BASE_PREL
llvm-svn: 236727
2015-05-07 13:44:51 +00:00
Denis Protivensky aaeba9ebb9 [ARM] llvm_unreachable => make_*_reloc_error in group relocs
llvm-svn: 236726
2015-05-07 13:41:44 +00:00
Denis Protivensky bc11ba4061 [ARM] Return directly from switch in relocation handler
llvm-svn: 236724
2015-05-07 13:12:11 +00:00
Denis Protivensky 9c3738ccef [ARM] Add return codes to relocation handlers
llvm-svn: 236723
2015-05-07 12:44:20 +00:00
Davide Italiano 06b21daf00 Revert unrelated chunk committed by accident in r236334.
The change is likely to be correct, but unrelated to the aforementioned
commit and needs a test to gets shipped. Sorry.

llvm-svn: 236336
2015-05-01 19:24:29 +00:00
Davide Italiano 9de946fa1f [ELF] Fix test for .init_array.
Change the test so that it tests the right functionality.
Also put a description with the code from which the test was generated.
Reported by Simon Atanasysan.

llvm-svn: 236334
2015-05-01 19:20:48 +00:00
Davide Italiano 0e4a3addf0 [ELF] Mark linker defined symbols as .hidden when needed.
I noticed that gold mark these as hidden. While at it I rewrote the test for
this feature to use yaml rather than an object file as input.

Differential Revision:	http://reviews.llvm.org/D9418
Reviewed by:	ruiu

llvm-svn: 236291
2015-05-01 00:07:11 +00:00
Davide Italiano f14fbcbf91 [GNU] Remove -x/-X from the list of options to be implemented.
llvm-svn: 236149
2015-04-29 20:35:58 +00:00
Rafael Espindola ed48e53d60 Use MemoryBufferRef instead of MemoryBuffer&. NFC.
This just reduces the noise from another patch.

llvm-svn: 235933
2015-04-27 22:48:51 +00:00
Rui Ueyama de9215e498 ELF: Simplify LinkerScript detection. NFC.
llvm-svn: 235895
2015-04-27 16:54:48 +00:00
Adhemerval Zanella d31aadf515 Add missing snippets from r235880
llvm-svn: 235890
2015-04-27 15:13:17 +00:00
Adhemerval Zanella 6bf4da02c1 ELF/ARM: Ignore R_ARM_V4BX for ARMv4 but allow linking
This patch allow the ARM relocation R_ARM_V4BX to be processed by lld,
although it is not really handled in the static relocation code.  The
relocation is in the form:

Relocation section '.rel.text' at offset 0x428 contains 4 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000014  00000028 R_ARM_V4BX

Meaning it does have a direct target, but rather references to an absolute
section *ABS* (in this exemple to the .text segment itself).  It makes the
target Atom after file parse to not have a associated pointer and thus
generating a derrefence NULL point in ELFFile<ELFT>::findAtom.  Current
approach is just ignore and return nullptr in such cases.

The problem relies that default GCC configuration
for arm-linux-gnueabi{hf} emits the relocation for the asm:

--
.syntax unified
.arm

.p2align 2
.type fn, %function
fn:
  ldr r3, .LGOT
  ldr r2, .LGOT+4
.LPIC:
  add r3, pc, r3
  ldr r2, [r3, r2]
  cmp r2, #0
  bxeq lr
  b __start__
.LGOT:
 .word _GLOBAL_OFFSET_TABLE_-(.LPIC+8)
 .word __start__(GOT)
--

But only with the option -march=armv4 (which is the default GCC configuration).
For arm5 and forward the relocation is not created. This a special relocation
(defined miscellaneous for ARM) that instruct the linker to replace the bx
instruction into a mov.  GNU linker has some options related to which substitution
it can create for such cases.

With this patch I can dynamically link an application against a GLIBC
arm-linux-gnueabi system configured with default GCC.

llvm-svn: 235880
2015-04-27 13:55:14 +00:00
Rafael Espindola 6759319c3c Use MemoryBufferRef instead of MemoryBuffer&. NFC.
This just reduces the noise from another patch.

llvm-svn: 235776
2015-04-24 21:10:50 +00:00
Rafael Espindola b597408da4 Simplify parseMemberFiles to take a single file.
llvm-svn: 235751
2015-04-24 19:08:51 +00:00
Rafael Espindola 773a159116 Simplify now that there is only one file. NFC.
llvm-svn: 235747
2015-04-24 19:01:30 +00:00
Rafael Espindola ab5696ba82 Return ErrorOr<std::unique_ptr<File>>. NFC.
llvm-svn: 235744
2015-04-24 18:51:30 +00:00
Rafael Espindola c1d535af05 Remove unused enum value. NFC.
llvm-svn: 235742
2015-04-24 18:36:57 +00:00
Rafael Espindola dedab912c3 Return an ErrorOr<std::unique_ptr<File>>. NFC.
llvm-svn: 235741
2015-04-24 18:33:50 +00:00