Commit Graph

481 Commits

Author SHA1 Message Date
Eugene Leviant ad270ec314 [ELF] Add armelf emulation mode
Differential revision: https://reviews.llvm.org/D34140

llvm-svn: 305375
2017-06-14 08:25:38 +00:00
Yuka Takahashi 1f1378dcbc Use getLastArgValue instead of getString
Summary: I found that getString defined in the LLD's Driver.cpp is
exactly the same as Arg::getLastArgValue defined in
llvm/Option/ArgLIst.h. This patch removes that local function and use
the function that the Arg class provides.

Reviewers: ruiu

Subscribers: emaste, llvm-commits

Differential Revision: https://reviews.llvm.org/D34196

llvm-svn: 305374
2017-06-14 08:01:26 +00:00
Rui Ueyama d3a4a3e3e4 Use StringRef::split instead of StringRef::find and StringRef::substr.
Summary: Pointed out by Yuka Takahashi.

Differential Revision: https://reviews.llvm.org/D34192

llvm-svn: 305364
2017-06-14 04:02:40 +00:00
Peter Collingbourne dc7936eced ELF: Move section merging before ICF. NFCI.
Differential Revision: https://reviews.llvm.org/D34093

llvm-svn: 305176
2017-06-12 00:00:51 +00:00
George Rimar 1840901a2f [ELF] - Allow producing -r output if only empty archive is given.
This is used by linux kernel build system.

(https://www.kernel.org/doc/Documentation/kbuild/makefiles.txt "3.2 Built-in object goals")

It has for example next configuration for linking built-in.o files:
drivers-y	:= $(patsubst %/, %/built-in.o, $(drivers-y))
drivers-$(CONFIG_PCI)		+= arch/ia64/pci/
...
drivers-$(CONFIG_OPROFILE)	+= arch/ia64/oprofile/

Im most simple case all CONFIG_* options are off. That means linker is called with empty input archive, 
emulation option and no inputs and expected to generate some relocatable output. 
ld.bfd is able to do that, we dont.

Patch allows to support this case.

Differential revision: https://reviews.llvm.org/D33937

llvm-svn: 305069
2017-06-09 12:26:57 +00:00
Dmitry Mikulin db3b87b2c0 Symbols re-defined with -wrap and -defsym need to be excluded from inter-
procedural optimizations to prevent dropping symbols and allow the linker
to process re-directs.

PR33145: --wrap doesn't work with lto.
Differential Revision: https://reviews.llvm.org/D33621

llvm-svn: 304719
2017-06-05 16:24:25 +00:00
Petr Hosek ffa786f465 [lld][ELF]Add option to make .dynamic read only
The .dynamic section of an ELF almost doesn't need to be written to with
the exception of the DT_DEBUG entry. For several reasons having a read
only .dynamic section would be useful. This change adds the -z keyword
"rodynamic" which forces .dynamic to be read-only. In this case DT_DEBUG
will not be emited.

Patch by Jake Ehrlich

Differential Revision: https://reviews.llvm.org/D33251

llvm-svn: 304024
2017-05-26 19:12:38 +00:00
Peter Collingbourne 968fe93803 ELF: The later of --build-id and --build-id= wins.
If the compiler driver passes --build-id and the user uses -Wl to
pass --build-id= then the user's flag should take precedence.

Differential Revision: https://reviews.llvm.org/D33461

llvm-svn: 303689
2017-05-23 21:16:48 +00:00
George Rimar ab94768cc1 [ELF] - Use llvm::to_integer() instead of StringRef::getAsInteger().
Switch to llvm::to_integer() everywhere in LLD instead of 
StringRef::getAsInteger() because API of latter is confusing. 
It returns true on error and false otherwise what makes reading 
the code incomfortable.

Differential revision: https://reviews.llvm.org/D33187

llvm-svn: 303149
2017-05-16 08:19:25 +00:00
Rafael Espindola 0f6cc65fe9 Remember OffsetInArchive in LazyObjectFile.
LazyObjectFile might turn out to be a BitcodeFile, so we need
OffsetInArchive.

llvm-svn: 302242
2017-05-05 15:17:07 +00:00
Rafael Espindola 0b1413a881 Use the archive offset with --whole-archive.
The test ELF/lto/thin-archivecollision.ll was not testing what it
wanted to test. It needs two archive members with the same name, but
different offsets.

Without this we could remove all references of OffsetInArchive and all
tests would still pass.

Fixing the test showed that the --whole-archive case was broken, which
this patch fixes.

llvm-svn: 302241
2017-05-05 15:08:06 +00:00
Rafael Espindola 80ae8ae186 Remember archive name when creating LazyObjectFile.
It is needed for creating an unique identifier for ThinLTO.

This fixes pr32931.

llvm-svn: 302235
2017-05-05 13:55:51 +00:00
Rui Ueyama b201a20eab Remove a comment that is no longer true.
llvm-svn: 302090
2017-05-03 23:10:33 +00:00
Rui Ueyama fd7deda57a Accept archive files with no symbol table instad of warning on them.
It seems virtually everyone who tries to do LTO build with Clang and
LLD was hit by a mistake to forget using llvm-ar command to create
archive files. I wasn't an exception. Since this is an annoying common
issue, it is probably better to handle that gracefully rather than
reporting an error and tell the user to redo build with different
configuration.

Differential Revision: https://reviews.llvm.org/D32721

llvm-svn: 302083
2017-05-03 21:03:08 +00:00
Rui Ueyama f13a6904b3 Make getArchiveMembers function a non-member function.
It didn't have to be a member function of Driver. This patch makes
that function a file-scoped non-member function.

llvm-svn: 301895
2017-05-02 02:57:45 +00:00
Rui Ueyama bd27849e4b Rename RPath Rpath for consistency. NFC.
For an option -foo-bar-baz, we have Config->FooBarBaz. Since -rpath is
-rpath and not -r-path, it should be Config->Rpath instead Config->RPath.

llvm-svn: 301759
2017-04-29 23:06:43 +00:00
Rui Ueyama 85a5e69ced Simplify by using getString instead of getLastArg. NFC.
llvm-svn: 301758
2017-04-29 22:56:38 +00:00
Rui Ueyama 543161a10c Report an error if --compress-debug-sections is given while zlib is not availble.
llvm-svn: 301757
2017-04-29 22:56:24 +00:00
Rui Ueyama cf8247ef48 Do flag compatibility check in checkOptions. NFC.
llvm-svn: 301476
2017-04-26 21:27:33 +00:00
Rui Ueyama 08af54c304 Factor out code to parse -build-id. NFC.
llvm-svn: 301475
2017-04-26 21:23:11 +00:00
Rui Ueyama 7163027884 Move code to emit error messages from Filesystem.cpp to Driver.cpp.
isFileWritable() checked if a file is writable and then emitted
an error message if it is not writable. So it did more than the
name says. This patch moves error() calls to Driver.

llvm-svn: 301422
2017-04-26 16:14:46 +00:00
George Rimar 9703ad2221 [ELF] - Implemented --defsym option.
gnu ld description of option is:

--defsym=symbol=expression
Create a global symbol in the output file, containing the absolute address given 
by expression. You may use this option as many times as necessary to define multiple
symbols in the command line. A limited form of arithmetic is supported for the 
expression in this context: you may give a hexadecimal constant or the name of an
existing symbol, or use "+" and "-" to add or subtract hexadecimal constants or 
symbols. If you need more elaborate expressions, consider using the linker command
language from a script. Note: there should be no white space between symbol, 
the equals sign ("="), and expression.

In compare with D32082, this patch does not support math expressions and absolute
symbols. It implemented via code similar to --wrap. That covers 1 of 3 possible
--defsym cases.

Differential revision: https://reviews.llvm.org/D32171

llvm-svn: 301391
2017-04-26 10:40:02 +00:00
Rui Ueyama 8d817f27e6 Make it explicit that -export-dynamic overrides -dynamic-list and -export-dynamic-symbol.
No functionality change.

llvm-svn: 301336
2017-04-25 17:40:12 +00:00
Rafael Espindola 3460cdd440 Remove DefaultSoName.
We can just use the existing SoName member variable. It now initially
contains what was in DefaultSoName and is modified if the .so has an
actual soname.

llvm-svn: 301259
2017-04-24 21:44:20 +00:00
Rui Ueyama 4627873807 Fallthrough to reduce code a bit. NFC.
llvm-svn: 300673
2017-04-19 11:31:45 +00:00
George Rimar dbf9339715 [ELF] - Implemented --compress-debug-sections option.
Patch implements --compress-debug-sections=zlib.

In compare with D20211 (a year old patch, abandoned), it implementation
uses streaming and fully reimplemented, does not support zlib-gnu for
simplification.

This is PR32308.

Differential revision: https://reviews.llvm.org/D31941

llvm-svn: 300444
2017-04-17 08:58:12 +00:00
Rui Ueyama 3233d3eb46 Do not initialize this->SoName with this->DefaultSoName.
This patch uses DefaultSoName in getSoName instead of in parseSoName.
I think this is more readable. This patch also add comments.

llvm-svn: 300147
2017-04-13 00:23:32 +00:00
Evgeniy Stepanov a76349bffe [lld] Keep full library path in DT_NEEDED.
Fixes PR32572.

When
    (a) a library has no soname
and (b) library is given on the command line with path (and not through -L/-l flags)
DT_NEEDED entry for such library keeps the path as given.

This behavior is consistent with gold and bfd, and is used in compiler-rt test suite.

This is a second attempt after r300007 got reverted. This time relro-omagic test is
changed in a way to avoid hardcoding the path to the test directory in the objdump'd
binary.

llvm-svn: 300011
2017-04-12 00:13:48 +00:00
Evgeniy Stepanov d512afe3da Revert "[lld] Keep full library path in DT_NEEDED."
This reverts commit r300007. Reason: breaks all the bots.

llvm-svn: 300008
2017-04-12 00:01:21 +00:00
Evgeniy Stepanov 2c2dcae13c [lld] Keep full library path in DT_NEEDED.
Fixes PR32572.

When
    (a) a library has no soname
and (b) library is given on the command line with path (and not through -L/-l flags)
DT_NEEDED entry for such library keeps the path as given.

This behavior is consistent with gold and bfd, and is used in compiler-rt test suite.

llvm-svn: 300007
2017-04-11 23:46:58 +00:00
Evgeniy Stepanov 6c973d647f [lld] --export-dynamic overrides --dynamic-list.
Fixes PR32573.

--export-dynamic exports everything, even in the presence of a --dynamic-list,
or --export-dynamic-symbol.

llvm-svn: 300002
2017-04-11 22:37:54 +00:00
Rui Ueyama 4eb2eccb24 Rename ScriptConfig::UndefinedSymbols ReferencedSymbols.
Symbols referenced by linker scripts are not necessarily be undefined,
so the previous name didn't convey the meaining of the variable.

llvm-svn: 299573
2017-04-05 18:02:30 +00:00
Rui Ueyama 2ec34544aa Move the parser for the linker script to a separate file.
LinkerScript.cpp contains both the linker script processor and the
linker script parser. I put both into a single file, but the file grown
too large, so it's time to put them into two different files.

llvm-svn: 299515
2017-04-05 05:07:39 +00:00
James Henderson b7a90ef48e [ELF] Fail the link early if the map file path is invalid
As with the changes made in r297645, we do not want a potentially long link to
be run, if it will ultimately fail because the map file is not writable. This
change reuses the same functionality as the output file path check. See
https://reviews.llvm.org/D30449 for further justification and explanations.

Reviewers: ruiu

Differential Revision: https://reviews.llvm.org/D31603

llvm-svn: 299420
2017-04-04 09:42:24 +00:00
Rui Ueyama 81cb710784 Update comments.
llvm-svn: 298669
2017-03-24 00:15:57 +00:00
Rui Ueyama 9b55e92a7f Move a few functions to a new file Filesystem.{cpp,h}.
llvm-svn: 298667
2017-03-24 00:15:16 +00:00
Rui Ueyama 0cbf1fd2f6 Fix varaible names that correspond to command line options.
llvm-svn: 298632
2017-03-23 18:16:42 +00:00
Petr Hosek 30f16b2339 [ELF] Allow references to reserved symbols in linker scripts
This requires collectign all symbols referenced in the linker script
and adding them to symbol table as undefined symbol.

Differential Revision: https://reviews.llvm.org/D31147

llvm-svn: 298577
2017-03-23 03:52:34 +00:00
Davide Italiano 7690721153 [ELF] Add -z nodlopen option.
Patch by Mark Kettenis.

llvm-svn: 298567
2017-03-23 00:54:16 +00:00
Rui Ueyama 4995afd943 Rename forEach -> parallelForEach and forLoop -> parallelFor.
"Parallel" is the most important aspect of the functions,
so we shouldn't omit that.

llvm-svn: 298557
2017-03-22 23:03:35 +00:00
Rui Ueyama bdc8bc047d Add "(compatible with GNU linkers)" to the -version output.
Previous output:

  $ ld.lld -version
  LLD 5.0.0

New output:

  $ ld.lld -version
  LLD 5.0.0 (compatible with GNU linkers)

Differential Revision: https://reviews.llvm.org/D31199

llvm-svn: 298532
2017-03-22 18:04:57 +00:00
Rui Ueyama 7ab38c3a12 Define Config::Is64.
This is a shorthand for Config->Wordsize == 8. So this is not strictly
necessary but seems handy. "Is 64 bit?" is easier to read than "Is
wordsize 8 byte?"

llvm-svn: 298463
2017-03-22 00:01:11 +00:00
Rui Ueyama a34da93847 Make elf::ScriptConfig a LinkerScript class member variable.
LinkerScript used to be a template class, so we couldn't instantiate
that class in elf::link. We instantiated ScriptConfig class earlier
instead so that the linker script parser can store configurations to
the object.

Now that LinkerScript is not a template, it doesn't make sense to
separate ScriptConfig from LinkerScript. This patch merges them.

llvm-svn: 298457
2017-03-21 23:03:09 +00:00
Rui Ueyama b8dd23f56e Rename LinkerScriptBase -> LinkerScript.
llvm-svn: 298456
2017-03-21 23:02:51 +00:00
Rui Ueyama f93ed4de2e Define Config::Endianness.
This is a shorthand for `Config->IsLE ? support::little : support::big`.

llvm-svn: 298445
2017-03-21 21:40:08 +00:00
George Rimar 76e562ab1b [ELF] - Detemplate InputSectionBase::uncompress(). NFC
llvm-svn: 298351
2017-03-21 09:08:58 +00:00
George Rimar a8dba48762 [ELF] - Combine LinkerScriptBase and LinkerScript<ELFT>
Patch removes templated linkerscript class.

Unfortunately that required 2 additional static methods
findSymbol() and addRegularSymbol() because code
depends on Symtab<ELFT>::X

Differential revision: https://reviews.llvm.org/D30982

llvm-svn: 298241
2017-03-20 10:09:58 +00:00
Rui Ueyama d57e74b7d3 Compute Config member function return values only once.
We had a few Config member functions that returns configuration values.
For example, we had is64() which returns true if the target is 64-bit.
The return values of these functions are constant and never change.

This patch is to compute them only once to make it clear that they'll
never change.

llvm-svn: 298168
2017-03-17 23:29:01 +00:00
Peter Collingbourne ee59e43f92 ELF: Add cache pruning support.
This patch causes us to use pruneCache() to prune the ThinLTO cache after
completing LTO. A new flag --thinlto-cache-policy allows users to configure
the policy.

Differential Revision: https://reviews.llvm.org/D31021

llvm-svn: 298036
2017-03-17 02:24:16 +00:00
Rui Ueyama 034a33a942 Remove a useless temporary variable.
llvm-svn: 297687
2017-03-13 23:26:37 +00:00