Commit Graph

711 Commits

Author SHA1 Message Date
Rui Ueyama b0f6c59023 Replace parallel arrays with a StringSwitch.
llvm-svn: 276163
2016-07-20 19:36:38 +00:00
Rui Ueyama 047404f711 Remove `else` after `break`.
llvm-svn: 276162
2016-07-20 19:36:36 +00:00
Rui Ueyama a7f7884df8 Simplify output section ownership.
This patch simplifies output section management by making
Factory class have ownership of sections that creates.

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

llvm-svn: 276141
2016-07-20 17:19:03 +00:00
George Rimar 31d842f55f [ELF] - Refactor of LinkerScript<ELFT>::getPhdrIndicesForSection
Previously it was harder to read and also has a error:
command kind was not checked.

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

llvm-svn: 276137
2016-07-20 16:43:03 +00:00
Eugene Leviant e63d81bd05 [ELF] Create output sections in LinkerScript class
llvm-svn: 276121
2016-07-20 14:43:20 +00:00
Rafael Espindola 74df5c7eeb Fix build with gcc 6.
llvm-svn: 275972
2016-07-19 12:33:46 +00:00
Eugene Leviant bbe3860244 [ELF] Minimal PHDRS parser and section to segment assignment support
llvm-svn: 275965
2016-07-19 09:25:43 +00:00
George Rimar b91e7118d4 Reformat comment from 3 to 2 lines. NFC.
llvm-svn: 275961
2016-07-19 07:42:07 +00:00
George Rimar 6ad330acaa Fixed comment. NFC.
llvm-svn: 275959
2016-07-19 07:39:07 +00:00
Eugene Leviant 0e36f42846 [ELF] Overriding reserved symbols in linker script
llvm-svn: 275549
2016-07-15 11:20:04 +00:00
Rui Ueyama 177746a739 Remove redundant `return`.
llvm-svn: 275528
2016-07-15 04:32:11 +00:00
Rui Ueyama 05ef4cff44 Merge SymbolAssignmentKind and ExprKind.
In a linker script, `.` is a special symbol indicating a counter.
Previously, we had two expression types, ExprKind and SymbolAssignmentKind
for `.` and all the other symbol names, respectively. But we could merge
them because the former is a special case of the latter.

llvm-svn: 275527
2016-07-15 04:19:37 +00:00
Eugene Leviant b030411414 [ELF] r275383 reverted due to buildbot failure
llvm-svn: 275385
2016-07-14 09:21:24 +00:00
Eugene Leviant 219d9b2b18 [ELF] Allow overriding reserved symbols in linker scripts
llvm-svn: 275383
2016-07-14 08:26:41 +00:00
Eugene Leviant eda81a1b86 [ELF] Support for symbol assignment in linker scripts within SECTIONS {} block
llvm-svn: 275158
2016-07-12 06:39:48 +00:00
Rafael Espindola 64c32d6f02 Fix formating. NFC.
llvm-svn: 274757
2016-07-07 14:28:47 +00:00
Rui Ueyama 52c4e17f8a Remove trailing whitespaces.
llvm-svn: 274343
2016-07-01 10:42:25 +00:00
Eugene Leviant 467c4d5538 [ELF] Fix first PT_LOAD segment VA calculation, when linker script is used
llvm-svn: 274342
2016-07-01 10:27:36 +00:00
Rui Ueyama 93c9af425e Create Strings.cpp and move string manipulation functions to that file.
llvm-svn: 274109
2016-06-29 08:01:32 +00:00
Rui Ueyama 722830a51b Rename matchStr -> globMatch.
llvm-svn: 274103
2016-06-29 05:32:09 +00:00
Davide Italiano 8e1131dc46 [ELF] Support for wildcard in version scripts.
Example:

VERSION_1.0 {
  global: foo*;
  local: *; }

now correctly matches all the symbols which name starts with
`foo`.

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

llvm-svn: 274091
2016-06-29 02:46:51 +00:00
Davide Italiano 47ae3c3e22 [LinkerScript] Spell 'character' correctly. NFC.
llvm-svn: 273817
2016-06-26 19:02:43 +00:00
Rui Ueyama 424b408165 Rename Align -> Alignment.
I think it is me who named these variables, but I always find that
they are slightly confusing because align is a verb.
Adding four letters is worth it.

llvm-svn: 272984
2016-06-17 01:18:46 +00:00
Dima Stepanov fb8978fc6a Fix the function to set the section VMA/LMA fields in case of using
the linker script. The cycle in the ELF/LinkerScript.cpp:assignAddresses()
routine will be used to go through all the sections and set all the
addresses correctly.

Add new test to check this case.

llvm-svn: 270090
2016-05-19 18:15:54 +00:00
George Rimar fbfe10f221 Removed dead code. NFC.
llvm-svn: 268497
2016-05-04 13:44:49 +00:00
George Rimar ab9390664f [ELF] - Implemented comparsion operators for linkerscript.
Patch adds support of <,>,!=,==,>=,<= operators.

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

llvm-svn: 267382
2016-04-25 08:14:41 +00:00
Rui Ueyama 9c1112d09a Use ScriptParserBase features to parse linker script expressions.
Previously, we have re-implemented utility functions such as `expect`
or `next` in LinkerScript.cpp. This patch reuses the existing
implementation that is in ScriptParser.cpp.

llvm-svn: 267255
2016-04-23 00:04:03 +00:00
Rui Ueyama 4a46539c24 Devirtualize ScriptParserBase. NFC.
ScriptParserBase class is a container of collection of various methods
to parse linker script-ish text. It had a virtual method `run` to run
the parser. But we don't have to enforce its descendents to implement
that. It's up to them.

This patch removes pure virtual function `run`.

llvm-svn: 267246
2016-04-22 22:59:24 +00:00
Rui Ueyama 5fa60985cf Inline getInteger as it's too short to be a function. NFC.
llvm-svn: 267219
2016-04-22 21:05:04 +00:00
Rui Ueyama e29a975d23 Update a comment for r267145.
llvm-svn: 267218
2016-04-22 21:02:27 +00:00
Rui Ueyama 0b3868ec6b Move uintX_t typedef to the class definition. NFC.
Now it is doable because LinkerScript is a template class.

llvm-svn: 267212
2016-04-22 20:41:07 +00:00
George Rimar dffc1410c5 [ELF] - Implemented linkerscript ALIGN command
ALIGN(exp)
Return the location counter (.) aligned to the next exp boundary. (https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/expressions.html)

Patch implements this command.
This fixes PR27406.

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

llvm-svn: 267145
2016-04-22 11:40:53 +00:00
George Rimar fba45c41df Recommitted r267132 "[ELF] - implemented ternary operator for linkerscript expressions"
With fix: removed redundant Dot parameter.

Original commit message:
[ELF] - implemented ternary operator for linkerscript expressions

Patch implements ternary operator for linkerscript expressions.
Like:

SECTIONS {
 . = 0x1 ? 0x2 : 0x3;
...
}

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

llvm-svn: 267140
2016-04-22 11:28:54 +00:00
George Rimar f8e230b277 Revert r267132 as it broke buildbot.
llvm-svn: 267134
2016-04-22 10:51:34 +00:00
George Rimar 8c4acddebc [ELF] - implemented ternary operator for linkerscript expressions
Patch implements ternary operator for linkerscript expressions.
Like:

SECTIONS {
 . = 0x1 ? 0x2 : 0x3;
...
}

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

llvm-svn: 267132
2016-04-22 10:35:34 +00:00
Rui Ueyama c9f402eadc Inline SectionRule::match.
This short function was used only once and didn't provide much value.

llvm-svn: 267086
2016-04-22 00:23:52 +00:00
Rui Ueyama c998a8c044 ELF: Make the special variable "." as a LinkerScript class member.
I will eventually make `evaluate` function a usual parse function
rather than a function that works on a separate token list.
This is the first step toward that.

llvm-svn: 267083
2016-04-22 00:03:13 +00:00
Rui Ueyama 8ec77e64fc ELF: Change how to handle KEEP linker script command.
You can instruct the linker to not discard sections even if they
are unused and --gc-sections option is given. The linker script
command for doing that is KEEP. The syntax is KEEP(foo) where foo
is a section name. KEEP commands are written in SECTIONS command,
so you can specify the order of sections *and* which sections
will be kept.

Each sub-command in SECTIONS command are translated into SectionRule
object. Previously, each SectionRule has `Keep` bit. However,
if you think about it, this hid information in too deep in elements
of a list. Semantically, KEEP commands aren't really related to
SECTIONS subcommands. We can keep the section list for KEEP in a
separate list. This patch does that.

llvm-svn: 267065
2016-04-21 22:00:51 +00:00
Rui Ueyama c3e2a4b006 ELF: Change the return type of getSectionOrder.
Also changed the function name and added comments.

llvm-svn: 267044
2016-04-21 20:30:00 +00:00
George Rimar dbbd8b15bf [ELF] - Use ArrayRef instead of std::vector& for LinkerScript module. NFC.
llvm-svn: 266978
2016-04-21 11:21:48 +00:00
George Rimar 71b26e94fd [ELF] - Get rid of SectionOrder array.
SectionOrder vector was a part of LinkerScript class.

It can be removed because Commands vector contains the 
same information and SectiorOrder is just a subset.

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

llvm-svn: 266974
2016-04-21 10:22:02 +00:00
Rui Ueyama 6011811beb Define and use a utility function. NFC.
llvm-svn: 266914
2016-04-20 20:54:13 +00:00
Rui Ueyama 99e519cdeb ELF: Redefine parseExpr to parse an expression. NFC.
Previously the function reads an operator and the rest of
the expressions. This patch makes it to actually parse an expression
which starts with a primary pexression followed by other expressions
concatenated with operators.

llvm-svn: 266912
2016-04-20 20:48:25 +00:00
Rui Ueyama 07320e4030 ELF: Template LinkerScript class.
Originally, linker scripts were basically an alternative way to specify
options to the command line options. But as we add more features to hanlde
symbols and sections, many member functions needed to be templated.
Now most the members are templated. It is probably time to template the
entire class.

Previously, LinkerScript is an executor of the linker script as well as
a storage of linker script configurations. This is not suitable to template
the class because when we are reading linker script files, we don't know
the ELF type yet, so we can't instantiate ELF-templated classes.

In this patch, I defined a new class, ScriptConfiguration, to store
linker script configurations. ScriptParser writes parse results to it,
and LinkerScript uses them.

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

llvm-svn: 266908
2016-04-20 20:13:41 +00:00
Rui Ueyama 0536ec0242 Make a function file-scoped.
llvm-svn: 266816
2016-04-19 20:50:25 +00:00
Rui Ueyama 7a81d674f6 Attempt to fix buildbot.
llvm-svn: 266799
2016-04-19 19:04:03 +00:00
Rui Ueyama 960504b91d ELF: Add +, -, *, / and & to SECTIONS linker script command.
This patch is based heavily on George Rimor's patch
http://reviews.llvm.org/D19221.

In the linker script, you can write expressions to compute addresses.
Currently we only support "+" operator. This adds a few more operators.

Since this patch adds * and /, we need to handle operator precedences
properly. I implemented that using the operator-precedence grammar.

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

llvm-svn: 266798
2016-04-19 18:58:11 +00:00
Rui Ueyama 9e957a0ac6 Rename LocationNode -> SectionsCommand.
They are called sections-command in the doc, so it is nice to keep
it consistent with it.
https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS

llvm-svn: 266668
2016-04-18 21:00:45 +00:00
Rui Ueyama 54115af45e Remove redundant curly braces.
llvm-svn: 266667
2016-04-18 21:00:43 +00:00
Rui Ueyama 7c18c28c97 Refactor LinkerScript::assignAddresses. NFC.
llvm-svn: 266666
2016-04-18 21:00:40 +00:00
George Rimar 652852c5c0 Recommitted 266457 with fix:
* Do script driven layout only if SECTIONS section exist.

Initial commit message:

[ELF] - Implemented basic location counter support.

This patch implements location counter support. 
It also separates assign addresses for sections to assignAddressesScript() if it scipt exists.

Main testcase is test/ELF/linkerscript-locationcounter.s, It contains some work with location counter. It is basic now.
Implemented location counter assignment and '+' operations.

Patch by myself with LOTS of comments and design suggestions from Rui Ueyama.

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

llvm-svn: 266526
2016-04-16 10:10:32 +00:00
Rui Ueyama faac567e68 Revert r266457: "[ELF] - Implemented basic location counter support."
This reverts commit r266457 as it breaks "hello world" both on
Linux and FreeBSD.

llvm-svn: 266485
2016-04-15 22:39:27 +00:00
George Rimar ea25877d4a [ELF] - Implemented basic location counter support.
This patch implements location counter support. 
It also separates assign addresses for sections to assignAddressesScript() if it scipt exists.

Main testcase is test/ELF/linkerscript-locationcounter.s, It contains some work with location counter. It is basic now.
Implemented location counter assignment and '+' operations.

Patch by myself with LOTS of comments and design suggestions from Rui Ueyama.

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

llvm-svn: 266457
2016-04-15 17:44:19 +00:00
Adhemerval Zanella e77b5bf69f [lld] [ELF] Add ScriptParserBase class
This patch add a base script tokenizer class to decouple parsing from
linker script handling.  The idea is to use this base class on dynamic
list parsing (--dynamic-list option). No functionality added.

llvm-svn: 265600
2016-04-06 20:59:11 +00:00
George Rimar 2348320d4e [ELF] - Teach linkerscript error handler to show full script line and column marker on error.
When error, this adds the text line of script to the output
and a marks exact incorrect token under it:

line 1: <error text here>
UNKNOWN_TAG {
      ^

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

llvm-svn: 265523
2016-04-06 08:08:40 +00:00
Rui Ueyama 38dc83417b Include line number in error message for linker scripts.
This patch is based on http://reviews.llvm.org/D18545 written
by George Rimar.

llvm-svn: 264878
2016-03-30 16:51:57 +00:00
Rui Ueyama 3ed2f06913 Fix spelling.
llvm-svn: 263358
2016-03-13 03:17:44 +00:00
George Rimar 777f96304e Recommit of r263252, [ELF] - Change all messages to lowercase to be consistent.
which was reverted because included
unrelative changes by mistake.

Original commit message:

[ELF] - Change all messages to lowercase to be consistent.

That is directly opposite to http://reviews.llvm.org/D18045,
which was reverted.

This patch changes all messages to start from lowercase letter if
they were not before.

That is done to be consistent with clang.

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

llvm-svn: 263337
2016-03-12 08:31:34 +00:00
Rui Ueyama f714955402 Revert r263252: "[ELF] - Change all messages to lowercase to be consistent."
This reverts commit r263252 because the change contained unrelated changes.

llvm-svn: 263272
2016-03-11 18:46:51 +00:00
George Rimar 96bcdae1a5 [ELF] - Change all messages to lowercase to be consistent.
That is directly opposite to http://reviews.llvm.org/D18045,
which was reverted.

This patch changes all messages to start from lowercase letter if
they were not before.

That is done to be consistent with clang.

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

llvm-svn: 263252
2016-03-11 16:40:55 +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
Rafael Espindola 0650192094 Revert "ELF: Add /lib and /usr/lib as default search paths."
It was causing errors like

/lib/libc.so.6 is incompatible with elf_x86_64

when linking on Fedora.

Every system has different default paths. It seems better to just trust
the driver to pass the correct -L options.

This reverts commit 262910.

llvm-svn: 262941
2016-03-08 17:13:12 +00:00
Rui Ueyama b9883d55d8 ELF: Add /lib and /usr/lib as default search paths.
GNU ld and gold have these paths as default search paths.
If you don't want these directories, pass -nostdlib.

llvm-svn: 262910
2016-03-08 04:06:27 +00:00
Rui Ueyama 3e80897627 ELF: Remove OutSection class and use a map instead.
It is easier to handle section filler data separately rather than
merging with section names.

llvm-svn: 262175
2016-02-28 05:09:11 +00:00
Rui Ueyama 7a6c9aed7a Simplify. NFC.
llvm-svn: 262174
2016-02-28 04:48:54 +00:00
Rafael Espindola e0df00b91f Rename elf2 to elf.
llvm-svn: 262159
2016-02-28 00:25:54 +00:00
George Rimar e2ee72b509 [ELF] - Implemented linkerscript sections padding.
BSD linker scripts contain special cases to add NOP
padding to code sections. Syntax is next:

.init:
 {
   KEEP (*(.init))
 } =0x90909090
(0x90 is NOP)

This patch implements that functionality.

llvm-svn: 262020
2016-02-26 14:48:31 +00:00
Rui Ueyama dc9cc6a574 Remove redundant template instantiations.
This class is used only in this translation unit, so no need
to instantiate them explicitly.

llvm-svn: 261951
2016-02-26 01:30:35 +00:00
George Rimar c3794e5834 [ELF] - replaced std::function with raw pointers in LinkerScript.cpp
Change as was proposed by David Blaikie.

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

llvm-svn: 261729
2016-02-24 09:21:47 +00:00
George Rimar cb2aeb66e4 [ELF] - Teach input section wildcard patterns to recognize '?' meta character.
`?' - matches any single character
https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html

This is used in linker scripts.

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

llvm-svn: 261726
2016-02-24 08:49:50 +00:00
George Rimar 481c2ce64b [ELF] - Linkerscript KEEP command.
When link-time garbage collection is in use (-gc-sections), it is 
often useful to mark sections that should not be eliminated. 
This is accomplished by surrounding an input section's wildcard 
entry with KEEP(). Patch implements that command.

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

llvm-svn: 261616
2016-02-23 07:47:54 +00:00
George Rimar d2389bfd9d Attemp to heal windows buildbot
http://lab.llvm.org:8011/builders/sanitizer-windows/builds/17414

llvm-svn: 261322
2016-02-19 11:56:49 +00:00
George Rimar f23b23200d [ELF] - Minor refactor of LinkerScript file
* Else-ifs in ScriptParser::run() replaced with std::function + map
* Reordered members of ScriptParser

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

llvm-svn: 261317
2016-02-19 10:45:45 +00:00
Rui Ueyama 1ebc8ed78a ELF: Add wildcard pattern matching to SECTIONS linker script command.
Each rule in SECTIONS commands is something like ".foo *(.baz.*)",
which instructs the linker to collect all sections whose name matches
".baz.*" from all files and put them into .foo section.

Previously, we didn't recognize the wildcard character. This patch
adds that feature.

Performance impact is a bit concerning because a linker script can
contain hundreds of SECTIONS rules, and doing pattern matching against
each rule would be too expensive. We could merge all patterns into
single DFA so that it takes O(n) to the input size. However, it is
probably too much at this moment -- we don't know whether the
performance of pattern matching matters or not. So I chose to
implement the simplest algorithm in this patch. I hope this simple
pattern matcher is sufficient.

llvm-svn: 260745
2016-02-12 21:47:28 +00:00
Rui Ueyama e9c5806593 ELF: Remove use of MapVector from LinkerScript.
We don't have to use a MapVector here. Instead, just std::vector suffices.

llvm-svn: 260724
2016-02-12 20:41:43 +00:00
Rui Ueyama f9de0d6904 ELF: Remove readLinkerScript and define LinkerScript::read instead.
llvm-svn: 260598
2016-02-11 21:38:55 +00:00
Rui Ueyama 717677af35 ELF: Create LinkerScript class to move code out of Writer.
Previously, we had code for linker scripts in Writer. This patch
separates that as LinkerScript class. The class provides a few
functions to query linker scripts and is also a container of some
linker-script-specific information.

Hopefully, Writer will only implement the default behavior and let
the new class handle gotchas regarding linker scripts.

llvm-svn: 260591
2016-02-11 21:17:59 +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
Rui Ueyama 025d59b16a ELF: Do not use fatal in LinkerScript.cpp.
This patch adds "Error" field to LinkerScript class. That field
is false by default, and set to true if there is a syntax error
in an input file. The linker script parser is a recursive-descedent
parser. Each function returns if Error is true -- so that
eventually the whole parser returns to a caller.

http://reviews.llvm.org/D16667

llvm-svn: 259557
2016-02-02 20:27:59 +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
Pete Cooper 6025933789 Fix bug in handling of quoted linker script tokens and update tests to use it.
There was an off by one error because the StringRef.substr functions
second argument is a length, not the end index.

Also updated a few ELF files which failed when run on Jenkins with paths
including the @ character.  This is often used in Jenkins for shared
workspace plugin.

Reviewed by Rui Ueyama

llvm-svn: 258583
2016-01-22 23:46:37 +00:00
Rui Ueyama 83cd6e00e9 Remove unnecessary `lld::`.
llvm-svn: 256970
2016-01-06 20:11:55 +00:00
Simon Atanasyan a1b8fc3bb4 [ELF] Lookup INPUT argument in the current directory
If an argument of the INPUT directive is a regular path, linker should
lookup it in the current folder first.

The fix does not contain any test cases because I think it is not a good
idea to pollute a current folder (which in general might be arbitrary)
by test files.

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

llvm-svn: 254178
2015-11-26 20:23:46 +00:00
Simon Atanasyan 16b0cc9ee6 [ELF] Reapply r254031 - LinkerScript: lookup absolute paths under sysroot
In case a sysroot prefix is configured, and the filename starts with
the '/' character, and the script being processed was located inside
the sysroot prefix, the file's name will be looked for in the sysroot
prefix. Otherwise, the linker falls to the common lookup scheme.

It is slightly modified version of the commit r254031. The problem of
the initial commit was in the `is_absolute` call. On Windows 'C:\' is
absolute path but we do not need to find it under sysroot. In this patch
linker looks up a path under sysroot only if the paths starts with '/'
character.

llvm-svn: 254135
2015-11-26 05:53:00 +00:00
Hans Wennborg 17436ce174 Follow-up to r254049; remove function I missed in the revert.
llvm-svn: 254052
2015-11-25 01:24:15 +00:00
Hans Wennborg 82d2d07ced Revert r254031: "ELF2: LinkerScript: lookup absolute paths under sysroot"
The test fails on Windows:

Command 34: "ld.lld" "-o" "D:\src\llvm\build.release\tools\lld\test\ELF\Output\l
inkerscript.s.tmp2" "D:\src\llvm\build.release\tools\lld\test\ELF\Output\linkers
cript.s.tmp.dir/xyz.script" "--sysroot=D:\src\llvm\build.release\tools\lld\test\
ELF\Output\linkerscript.s.tmp.dir"
Command 34 Result: 1
Command 34 Output:

Command 34 Stderr:
Unable to find /libxyz.a

llvm-svn: 254049
2015-11-25 00:58:31 +00:00
Rui Ueyama a7e09c6221 ELF2: Factor out isUnderSysroot from readLinkerScript. NFC.
llvm-svn: 254032
2015-11-24 22:26:33 +00:00
Simon Atanasyan 44136b675d ELF2: LinkerScript: lookup absolute paths under sysroot
In case a sysroot prefix is configured, and the filename starts with the
'/' character, and the script being processed was located inside the
sysroot prefix, the file's name will be looked for in the sysroot
prefix. Otherwise, the linker falls to the common lookup scheme.

https://www.sourceware.org/binutils/docs-2.24/ld/File-Commands.html

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

llvm-svn: 254031
2015-11-24 22:16:25 +00:00
Denis Protivensky 8e3b38aba1 [ELF2] SECTIONS command basic support
* determine output section by input section name
* discard input sections
* order output sections accordingly

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

llvm-svn: 252868
2015-11-12 09:52:08 +00:00
George Rimar 83f406cff5 [ELF2] - Linker script EXTERN command implemented.
The reason of collecting all undefines in vector is that during reading files we already need to have Symtab created. Or like was done in that patch - to put undefines from scripts somewhere to delay Symtab.addUndefinedOpt() call.

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

llvm-svn: 250711
2015-10-19 17:35:12 +00:00
Davide Italiano 10d268d62c [ELF2/Linkerscript] Skip semicolon in linker directives parsing.
The documentation says: "You may separate commands using semicolons",
so they seem to be optional.

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

llvm-svn: 250223
2015-10-13 20:48:56 +00:00
Rui Ueyama 34f2924675 ELF2: Add comments.
llvm-svn: 250215
2015-10-13 19:51:57 +00:00
Rafael Espindola 7f10746be0 Remove unnecessary include.
llvm-svn: 250161
2015-10-13 14:54:49 +00:00
Rui Ueyama f03f3cc18c Use llvm::sys::path::is_absolute instead of my own.
llvm-svn: 250133
2015-10-13 00:09:21 +00:00
Rui Ueyama 63d8880b38 Fix test breakage on Windows.
llvm-svn: 250127
2015-10-12 23:49:04 +00:00
Davide Italiano 9159ce9327 [ELF2/LinkerScript] Implement parsing of OUTPUT_ARCH() command.
Differential Revision:	 http://reviews.llvm.org/D13675

llvm-svn: 250115
2015-10-12 21:50:08 +00:00
Davide Italiano 6836c6182d [ELF2/LinkerScript] Fix OUTPUT_FORMAT directive parsing
Differential Revision:	 http://reviews.llvm.org/D13668

llvm-svn: 250106
2015-10-12 21:08:41 +00:00
Rui Ueyama 1c42afcbdc Remove explicit Twine instantiation if possible.
llvm-svn: 250055
2015-10-12 15:49:06 +00:00
Rui Ueyama 35da9b6e1c ELF2: Implement --as-needed.
This patch adds AsNeeded and IsUsed bool fields to SharedFile. AsNeeded bit
is set if the DSO is enclosed with --as-needed and --no-as-needed. IsUsed
bit is off by default. When we adds a symbol to the symbol table for dynamic
linking, we set its SharedFile's IsUsed bit.

If AsNeeded is set but IsUsed is not set, we don't want to write that
file's SO name to DT_NEEDED field.

http://reviews.llvm.org/D13579

llvm-svn: 249998
2015-10-11 20:59:12 +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 a47ee68d8e ELF2: Do not leak MemoryBuffers.
llvm-svn: 249962
2015-10-11 01:53:04 +00:00
Rui Ueyama 00f972728b ELF2: LinkerScript: Handle INPUT as a synonym for GROUP.
In our name resolution algorithm, --start-group and --end-group have
no special meaning.

llvm-svn: 249961
2015-10-11 01:31:57 +00:00
Rui Ueyama 31aa1f83de ELF2: LinkerScript: Implement INCLUDE directive.
llvm-svn: 249960
2015-10-11 01:31:55 +00:00
Davide Italiano 68a39a6565 [ELF2] Implement linker script SEARCH_DIR() directive.
llvm-svn: 249707
2015-10-08 17:51:41 +00:00
Denis Protivensky 90c5099e8a [ELF2] Add ENTRY command to the linker script
Set ENTRY as an entry point if -e is not specified.

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

llvm-svn: 249661
2015-10-08 06:48:38 +00:00
Rui Ueyama ee59282bfd ELF2: Implement OUTPUT() linker script directive.
llvm-svn: 249491
2015-10-07 00:25:09 +00:00
Rui Ueyama 983ed2b749 ELF2: Define Driver::addFile() as a one-stop place to open a file.
Opening a file and dispatching to readLinkerScript() or createFile()
is a common operation. We want to use that at least from Driver and
from LinkerScript. In COFF, we had the same problem. This patch
resolves the problem in the same way as we did for COFF.

Now, if you have a path that you want to open, just call
Driver->addFile(StringRef). That function opens the file and handles
that as if that were given by command line. This function is the
only place we call identify_magic().

llvm-svn: 249023
2015-10-01 15:23:09 +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