Commit Graph

671 Commits

Author SHA1 Message Date
Pete Cooper 9b28a4559e Add cmdline options for LC_DATA_IN_CODE load command.
Also added the defaults for whether to generate this load command, which
the cmdline options are able to override.

There was also a difference to ld64 which is fixed here in that ld64 will
generate an empty data in code command if requested.

rdar://problem/24472630

llvm-svn: 260191
2016-02-09 02:10:39 +00:00
Pete Cooper 41f3e8e408 Generate LC_FUNCTION_STARTS load command.
This load command generates data in the LINKEDIT section which
is a list of ULEB128 delta's to all of the functions in the __text section.

It is then 0 terminated and pointer aligned to pad.

ld64 exposes the -function-starts and no-function-starts cmdline options
to override behaviour from the defaults based on file types.

rdar://problem/24472630

llvm-svn: 260188
2016-02-09 01:38:13 +00:00
Pete Cooper 40576fa0e9 Add support for the source_version cmdline option.
This is of the form A.B.C.D.E and to match ld64's behaviour, is
always output to files, even when the version is 0.

rdar://problem/24472630

llvm-svn: 259746
2016-02-04 02:45:23 +00:00
Pete Cooper 3dd478a9c9 Default to an unknown OS instead of MacOSX.
Defaulting to unknown matches ld64, but it also makes sure that all
of our code can handle not knowing the platform.  For example, a later
commit will add support for version min load commands with an unknown
platform, which is a feature supported by ld64.

No test case here.  The next commit will have one with the version min
code that needed this patch.

llvm-svn: 259739
2016-02-04 01:57:59 +00:00
Pete Cooper 451ec4b68e Add support for -sdk_version cmdline option.
This option is emitted in the min_version load commands.

Note, there's currently a difference in behaviour compared to ld64 in
that we emit a warning if we generate a min_version load command and
didn't give an sdk_version.  We need to decide what the correct behaviour
is here as its possible we want to emit an error and force clients to
provide the option.

llvm-svn: 259729
2016-02-03 23:39:05 +00:00
Pete Cooper 354809e139 Add generation of LC_VERSION_MIN load commands.
If the command line contains something like -macosx_version_min and we
don't explicitly disable generation with -no_version_load_command then
we generate the LC_VERSION_MIN command in the output file.

There's a couple of FIXME's in here.  These will be handled soon with
more tests but I didn't want to grow this patch any more than it already was.

rdar://problem/24472630

llvm-svn: 259718
2016-02-03 22:28:29 +00:00
Rui Ueyama b6940115a8 ELF: Make link() to take an output stream to which error messages are written.
http://reviews.llvm.org/D16668

llvm-svn: 259597
2016-02-02 22:49:32 +00:00
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
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 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 2735783090 Add the GC commandline options and throw errors if they are used
llvm-svn: 257907
2016-01-15 17:39:02 +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 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 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
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
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
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
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 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
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 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
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
Rafael Espindola f0461ba985 Update for llvm api change.
llvm-svn: 244856
2015-08-13 01:07:08 +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
Rui Ueyama 8c484af217 COFF: Remove lld-link2 alias.
llvm-svn: 244358
2015-08-07 21:02:36 +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
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
Michael J. Spencer bae540e945 Revert ELF port. Posting to mailing list.
llvm-svn: 242118
2015-07-14 04:49:48 +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
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
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 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
Rafael Espindola 9bd82e9952 Update for llvm api change.
llvm-svn: 239671
2015-06-13 12:50:13 +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
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