Commit Graph

100 Commits

Author SHA1 Message Date
Rafael Espindola 3d6d4c39be Handle the -T option.
We were not reading it or including in the --reproduce archive.

llvm-svn: 271367
2016-06-01 06:17:27 +00:00
Rui Ueyama fe65877c76 Reorganize the cpio archiver as CpioFile class. NFC.
This code separates the code to create cpio archive from the driver.

llvm-svn: 269593
2016-05-15 17:10:23 +00:00
Rui Ueyama 9194db78fb Support --build-id=0x<hexstring>.
If you specify the option in the form of --build-id=0x<hexstring>,
that hexstring is set as a build ID. We observed that the feature
is actually in use in some builds, so we want this feature.

llvm-svn: 269495
2016-05-13 21:55:56 +00:00
Rafael Espindola f72914f42a Add a link to the format description.
llvm-svn: 269102
2016-05-10 19:26:55 +00:00
Rui Ueyama af2312feb7 Make --reproduce to not produce undesired whitespace.
Fixes bug 27648.

llvm-svn: 268569
2016-05-04 23:12:55 +00:00
Rafael Espindola 2c51e619d5 Print the cpio trailer after every member.
This is both simpler and safer. If we crash at any point, there is a
valid cpio file to reproduce the crash.

Thanks to Rui for the suggestion.

llvm-svn: 268495
2016-05-04 12:47:56 +00:00
Rafael Espindola 1dd2b3d1d0 Produce cpio files for --reproduce.
We want --reproduce to

* not rewrite scripts and thin archives
* work with absolute paths

Given that, it pretty much has to create a full directory tree. On windows that
is problematic because of the very short maximum path limit. On most cases
users can still work around it with "--repro c:\r", but that is annoying and
not viable for automated testing.

We then need to produce some form of archive with the files. The first option
that comes to mind is .a files since we already have code for writing them.
There are a few problems with them

The format has a dedicated string table, so we cannot start writing it until
all members are known.
Regular implementations don't support creating directories. We could make
llvm-ar support that, but that is probably not a good idea.
The next natural option would be tar. The problem is that to support long path
names (which is how this started) it needs a "pax extended header" making this
an annoying format to write.

The next option I looked at seems a natural fit: cpio files.

They are available on pretty much every unix, support directories and long path
names and are really easy to write. The only slightly annoying part is a
terminator, but at least gnu cpio only prints a warning if it is missing, which
is handy for crashes. This patch still makes an effort to always create it.

llvm-svn: 268404
2016-05-03 17:30:44 +00:00
Rafael Espindola 133ebe5bc7 Simplify. NFC.
llvm-svn: 268324
2016-05-02 22:52:15 +00:00
Rui Ueyama 5002a67ef2 Remove unnecessary namespace specifiers.
llvm-svn: 268292
2016-05-02 19:59:56 +00:00
Rui Ueyama fc28827216 Remove unnecessary namespace specifiers.
llvm-svn: 268278
2016-05-02 18:51:08 +00:00
Rui Ueyama ff12f23080 Attempt to fix Windows bots.
llvm-svn: 268275
2016-05-02 18:16:14 +00:00
Rui Ueyama 2664d45267 Fix --reproduce for --export-dynamic-symbol.
--export-dynamic-symbol doesn't take path.

llvm-svn: 268273
2016-05-02 18:12:09 +00:00
Rui Ueyama e951a1d739 Quote arguments for --reproduce.
llvm-svn: 268258
2016-05-02 17:34:17 +00:00
Rafael Espindola e85bcbd1c3 Don't include the output dir in the response file.
With this it is possible to use chroot/fakechroot to have a completely
reproducible link even when thin archives or linker scripts have
absolute paths.

llvm-svn: 268231
2016-05-02 14:12:35 +00:00
Rafael Espindola 21e1489048 Don't quote "--hash-style gnu".
Otherwise lld fails to use the response file.

llvm-svn: 268225
2016-05-02 13:00:42 +00:00
Rui Ueyama 2796ae3f69 ELF: --reproduce: quote pathnames for -L and other options.
Previously, arguments for options that take pathnames were not rewritten.

llvm-svn: 268172
2016-04-30 22:46:47 +00:00
Rui Ueyama 9aea957f6d ELF: --reproduce: Copy files referenced by linker scripts.
Previuosly, only files appeared on the command line were copied.

llvm-svn: 268171
2016-04-30 22:23:29 +00:00
Rui Ueyama 38aa57d966 Attempt to fix Windows buildbots.
llvm-svn: 268170
2016-04-30 22:20:27 +00:00
Rui Ueyama aa00e96a84 ELF: Make --reproduce to produce a response file.
The aim of this patch is to make it easy to re-run the command without
updating paths in the command line. Here is a use case.

Assume that Alice is having an issue with lld and is reporting the issue
to developer Bob. Alice's current directly is /home/alice/work and her
command line is "ld.lld -o foo foo.o ../bar.o". She adds "--reproduce repro"
to the command line and re-run. Then the following text will be produced as
response.txt (notice that the paths are rewritten so that they are
relative to /home/alice/work/repro.)

  -o home/alice/work/foo home/alice/work/foo.o home/alice/bar.o

The command also produces the following files by copying inputs.

  /home/alice/repro/home/alice/work/foo.o
  /home/alice/repro/home/alice/bar.o

Alice zips the directory and send it to Bob. Bob get an archive from Alice
and extract it to his home directory as /home/bob/repro. Now his directory
have the following files.

  /home/bob/repro/response.txt
  /home/bob/repro/home/alice/work/foo.o
  /home/bob/repro/home/alice/bar.o

Bob then re-run the command with these files by the following commands.

  cd /home/bob/repro
  ld.lld @response.txt

This command will run the linker with the same command line options and
the same input files as Alice's, so it is very likely that Bob will see
the same issue as Alice saw.

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

llvm-svn: 268169
2016-04-30 21:40:04 +00:00
Rui Ueyama cf0dd1ebf2 Move utility functions to DriverUtils.cpp.
llvm-svn: 267602
2016-04-26 20:41:32 +00:00
Rui Ueyama 8fe7ce5903 Variable names should start with uppercase letters.
llvm-svn: 265239
2016-04-02 19:15:26 +00:00
Rui Ueyama 319d7304c3 Simplify. NFC.
llvm-svn: 264785
2016-03-29 20:53:21 +00:00
Rui Ueyama 15fa035477 ELF: Fix use-after-free problem.
Fixes pr26908. This patch is based on Filipe Cabecinhas'
patch (http://reviews.llvm.org/D18167)

http://reviews.llvm.org/D18169

llvm-svn: 263569
2016-03-15 18:20:50 +00:00
Rui Ueyama 5bc2acd052 Print out newline in both cases.
llvm-svn: 263401
2016-03-13 23:07:42 +00:00
George Rimar 5761042db7 This reverts the r263125
It was discussed to make all messages be 
lowercase to be consistent with clang.
(also reverts the r263128 which fixed 
build bot fail after r263125)

Original commit message:
[ELF] - Consistent spelling for error/warning messages

Previously error and warnings were not consistent in lld.
Some of them started from lowercase letter, others from
uppercase. Also there was one or two which had a dot at the end.
This patch changes all messages to start from uppercase letter if
they were not before.

Differential revision: http://reviews.llvm.org/D18045

llvm-svn: 263240
2016-03-11 14:43:02 +00:00
George Rimar e094388861 [ELF] - Consistent spelling for error/warning messages
Previously error and warnings were not consistent in lld.
Some of them started from lowercase letter, others from
uppercase. Also there was one or two which had a dot at the end.
This patch changes all messages to start from uppercase letter if
they were not before.

Differential revision: http://reviews.llvm.org/D18045

llvm-svn: 263125
2016-03-10 16:58:34 +00:00
Rui Ueyama 1eb9f44118 ELF: Add --help option.
llvm-svn: 262168
2016-02-28 03:18:09 +00:00
Rui Ueyama 1abcf370fd ELF: Add --version option.
llvm-svn: 262167
2016-02-28 03:18:07 +00:00
Rafael Espindola e0df00b91f Rename elf2 to elf.
llvm-svn: 262159
2016-02-28 00:25:54 +00:00
Rui Ueyama 21eecb4f14 Re-submit ELF: Report multiple errors from the driver.
This reverts r259395 which reverted r259143.

llvm-svn: 259572
2016-02-02 21:13:09 +00:00
Nico Weber f07bd3b72d Revert r259143, it broke check-lld on Windows (see PR26388).
llvm-svn: 259395
2016-02-01 20:03:53 +00:00
Rui Ueyama 1940424632 ELF: Report multiple errors from the driver.
This patch let the driver keep going until it parses all
command line options.

http://reviews.llvm.org/D16645

llvm-svn: 259143
2016-01-29 01:54:52 +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
Rui Ueyama 83cd6e00e9 Remove unnecessary `lld::`.
llvm-svn: 256970
2016-01-06 20:11:55 +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
George Rimar 4a8c93ee85 [elf2] - remove redundant check.
This one is not needed anymore after r250812

llvm-svn: 250818
2015-10-20 11:27:00 +00:00
George Rimar b7d79b5c27 [ELF2] Fixed crash when no library is specified for -l
llvm-svn: 250811
2015-10-20 09:58:56 +00:00
Rui Ueyama c6e1b97161 ELF2: Remove ArgParser class and define parseArgs() function instead.
ArgParser was a class with only one member function, so it didn't
have to be a class.

llvm-svn: 249988
2015-10-11 18:19:01 +00:00
Rui Ueyama 52a1509ea7 ELF2: LinkerScript: Interpret -l and = file name prefixes.
In the linker script, -l and = have the same meaning as in the command line.
In addition to that, if a path is not absolute, the path needs to be searched
from the search paths. This patch implements them.

llvm-svn: 249967
2015-10-11 03:28:42 +00:00
Rui Ueyama 4b02ca99d0 ELF: Move utility functions from Driver to DriverUtils.
llvm-svn: 249966
2015-10-11 03:28:39 +00:00
Rui Ueyama b973256683 ELF2: Manage BumpPtrAllocator ownership better.
Previously, each ArgParser owned a BumpPtrAllocator, and arguments parsed
by an ArgParser would refer strings allocated using the BumpPtrAllocator
only when response files were used. This could cause a subtle bug because
such ownership was not obvious.

This patch moves the ownership from ArgParser to Driver and make the
ownership explicit.

llvm-svn: 249963
2015-10-11 01:53:07 +00:00
Rui Ueyama f7c5fbb1ca ELF2: Create LinkerScript.cpp and move code from DriverUtils to there.
llvm-svn: 248920
2015-09-30 17:23:26 +00:00
Rui Ueyama bf506b7d48 ELF2: LinkerScript: Handle quoted tokens.
llvm-svn: 248919
2015-09-30 17:15:29 +00:00
Rui Ueyama f5c4aca98f ELF2: Add basic linker script support.
This linker script parser and evaluator is powerful enough to read
Linux's libc.so, which is (despite its name) a linker script that
contains OUTPUT_FORMAT, GROUP and AS_NEEDED directives.

The parser implemented in this patch is a recursive-descendent one.
It does *not* construct an AST but consumes directives in place and
sets the results to Symtab object, like what Driver is doing.
This should be very fast since less objects are allocated, and
this is also more readable.

http://reviews.llvm.org/D13232

llvm-svn: 248918
2015-09-30 17:06:09 +00:00
Rui Ueyama eeb22f8251 ELF2: Support reponse files.
http://reviews.llvm.org/D13148

llvm-svn: 248575
2015-09-25 15:37:33 +00:00
Rui Ueyama d5b5ab7638 [ELF2] Output of all unknown arguments instead of only one.
Patch from George Rimar!

llvm-svn: 248524
2015-09-24 18:55:33 +00:00
Rafael Espindola 192e1fa59d Move the error handling functions to Error.h. NFC.
llvm-svn: 244216
2015-08-06 15:08:23 +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