Commit Graph

711 Commits

Author SHA1 Message Date
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 fc16173ceb Sort. NFC.
llvm-svn: 298447
2017-03-21 21:49:16 +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
Rafael Espindola 195f23c53b Inline a few functions.
I don't foresee having to makes these functions any stricter or
fancier, so it probably makes sense to inline them.

llvm-svn: 298252
2017-03-20 14:35:41 +00:00
Rafael Espindola 49592cf679 Initialize dot.
This would fix an initialized error found by msan. The error is not
showing after r298241, but it is not clear why.

llvm-svn: 298251
2017-03-20 14:33:33 +00:00
George Rimar b17d16a2a1 [ELF] - Reuse Config->IsLE. NFC.
llvm-svn: 298242
2017-03-20 10:16:57 +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
George Rimar 009833d377 [ELF] - Apply clang-format. NFC.
llvm-svn: 298240
2017-03-20 09:51:18 +00:00
Rafael Espindola 7ba5f47eb8 Handle & and | of non abs values.
Handling & in particular is probably important because of its use in
aligning addresses.

llvm-svn: 298096
2017-03-17 14:55:36 +00:00
Rafael Espindola 5f08a1dca8 Refuse to add two non absolute symbols.
Since there is no way to produce the correct answer at runtime, it is
probably better to just err.

llvm-svn: 298094
2017-03-17 14:51:07 +00:00
Rafael Espindola f2115f04c8 Support non abs values in the rhs of +.
llvm-svn: 298088
2017-03-17 13:45:36 +00:00
Rafael Espindola 72dc195d78 Change our linker script expr representation.
This fixes pr32031 by representing the expressions results as a
SectionBase and offset. This allows us to use an input section
directly instead of getting lost trying to compute an offset in an
outputsection when not all the information is available yet.

This also creates a struct to represent the *value* of and expression,
allowing the expression itself to be a simple typedef. I think this is
easier to read and will make it easier to extend the expression
computation to handle more complicated cases.

llvm-svn: 298079
2017-03-17 13:05:04 +00:00
Rafael Espindola 490fccb170 Remove unnecessary (). NFC.
llvm-svn: 298076
2017-03-17 13:00:45 +00:00
George Rimar f64618a621 [ELF] - Detemplate SymbolBody::getVA and SymbolBody::getPltVA. NFC.
llvm-svn: 298071
2017-03-17 11:56:54 +00:00
Rui Ueyama 98e55de699 Revert r297850: [ELF] - Linkerscript: make Dot public and remove getDot(). NFC.
This reverts commit r297850 because this change was made
based on a miscommunication.

llvm-svn: 298001
2017-03-16 21:50:30 +00:00
George Rimar 69268a8ab3 [ELF] - Detemplate SymbolBody::getOutputSection(). NFC.
llvm-svn: 297943
2017-03-16 11:06:13 +00:00
George Rimar 20055d4cd2 [ELF] - Linkerscript: make Dot public and remove getDot(). NFC.
Suggested by Rui Ueyama,
also groups member variables in a single place, while I am here.

llvm-svn: 297850
2017-03-15 16:07:02 +00:00
George Rimar 503206c567 [ELF] - Move LinkerScript::discard to LinkerScriptBase. NFC.
Became possible after r297844

llvm-svn: 297848
2017-03-15 15:42:44 +00:00
Petr Hosek 02ad516b2e Support ABSOLUTE on the right hand side in linker scripts
This also requires postponing the assignment the assignment of
symbols defined in input linker scripts since those can refer to
output sections and in case we don't have a SECTIONS command, we
need to wait until all output sections have been created and
assigned addresses.

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

llvm-svn: 297802
2017-03-15 03:33:23 +00:00
George Rimar a2a1ef1abc [ELF] - Move members of LinkerScript to LinkerScriptBase. NFC.
That moves all members that s possible to move for now (all which
does not depend on ELFT templating).

After that change LinkerScript contains only 8 methods in total,
and I believe it is possible to move them all after tweaking other
parts of linker. And we will be able to have single class for 
linkerscript at the end.

llvm-svn: 297735
2017-03-14 12:03:34 +00:00
George Rimar 23e6a02450 [ELF] - Remove unnecessary template #6. NFC.
llvm-svn: 297734
2017-03-14 11:31:28 +00:00
George Rimar f7f0d08827 [ELF] - Remove unnecessary template #5. NFC.
llvm-svn: 297732
2017-03-14 11:23:33 +00:00
George Rimar d83ce1b49d [ELF] - Devirtualize LinkerScriptBase::getOutputSectionSize. NFC.
It does not use ELFT templates so can be non-virtual.

llvm-svn: 297727
2017-03-14 10:24:47 +00:00
George Rimar 851dc1e84d [ELF] - Devirtualize LinkerScriptBase::getOutputSection
It does not use ELFT templates so can be non-virtual.

llvm-svn: 297725
2017-03-14 10:15:53 +00:00
George Rimar 0c1c8085bc [ELF] - Move ThreadBssOffset and Dot to LinkerScriptBase. NFC.
One more step to combine LinkerScript and LinkerScriptBase.

llvm-svn: 297722
2017-03-14 10:00:19 +00:00
George Rimar e21c3af7e9 [ELF] - Remove unnecessary template #4. NFC.
OutputSectionFactory has no ELFT templates anymore.

llvm-svn: 297720
2017-03-14 09:30:25 +00:00
George Rimar 2d2621090d [ELF] - Step to combine LinkerScript and LinkerScriptBase
We can move all not templated functionality to LinkerScriptBase.
Patch do that for hasPhdrsCommands() and shows how it helps to detemplate
things in other places.

Probably we should be able to merge these 2 classes into single one after such steps.
Even if not, it still looks as reasonable cleanup for me.

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

llvm-svn: 297714
2017-03-14 09:03:53 +00:00
Eugene Leviant 5784e96f5c [ELF] Fix LMA offset calculation
Differential revision: https://reviews.llvm.org/D30832

llvm-svn: 297713
2017-03-14 08:57:09 +00:00
George Rimar 78aa270041 [ELF] - Remove unnecessary template. NFC.
llvm-svn: 297622
2017-03-13 14:40:58 +00:00
Rafael Espindola 4595df94bb Don't pass Dot to every callback.
It is available from ScriptBase.

llvm-svn: 297472
2017-03-10 16:04:26 +00:00
Rafael Espindola 9bd4566dac Use SectionBase for linker script expressions.
This is a small step for fixing pr32031, which needs expressions that
point to input sections.

llvm-svn: 297431
2017-03-10 00:47:33 +00:00
Rui Ueyama f5fce48679 Handle ":" as a regular token character in linker scripts.
This is an alternative to https://reviews.llvm.org/D30500 to simplify the
version definition parser and allow ":" in symbol names.

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

llvm-svn: 297402
2017-03-09 19:23:00 +00:00
Rafael Espindola 5616adf655 Remove DefinedSynthetic.
With this we have a single section hierarchy. It is a bit less code,
but the main advantage will be in a future patch being able to handle

foo = symbol_in_obj;

in a linker script. Currently that fails since we try to find the
output section of symbol_in_obj.  With this we should be able to just
return an InputSection from the expression.

llvm-svn: 297313
2017-03-08 22:36:28 +00:00
Rafael Espindola 76b6bd355d Remove unnecessary template. NFC.
llvm-svn: 297287
2017-03-08 15:44:30 +00:00
Rafael Espindola 3770763cda Rename Addralign to Alignment.
It now matches the name used in InputSectionBase.

llvm-svn: 297144
2017-03-07 14:55:52 +00:00
Rafael Espindola bedccb5e78 Simplify. NFC.
llvm-svn: 296620
2017-03-01 14:21:31 +00:00
Rafael Espindola bd12e2a0ce Simplify. NFC.
llvm-svn: 296619
2017-03-01 14:12:21 +00:00
Rui Ueyama 80474a26b9 De-template DefinedRegular.
Differential Revision: https://reviews.llvm.org/D30348

llvm-svn: 296508
2017-02-28 19:29:55 +00:00
Rui Ueyama 968db48cee Move SymbolTableSection::getOutputSection to SymbolBody::getOutputSection.
That function doesn't use any member of SymbolTableSection, so I
couldn't see a reason to make it a member of that class. The function
takes a SymbolBody, so it is more natural to make it a member of
SymbolBody.

llvm-svn: 296433
2017-02-28 04:02:42 +00:00
Rui Ueyama 9320cb0719 De-template SyntheticSection.
This class didn't use ELFT.

llvm-svn: 296313
2017-02-27 02:56:02 +00:00
Rui Ueyama 536a26706f Move SymbolTable<ELFT>::Sections out of the class.
The list of all input sections was defined in SymbolTable class for a
historical reason. The list itself is not a template. However, because
SymbolTable class is a template, we needed to pass around ELFT to access
the list. This patch moves the list out of the class so that it doesn't
need ELFT.

llvm-svn: 296309
2017-02-27 02:32:08 +00:00
Rui Ueyama 02a036f2e6 De-template OutputSectionFactory.
Since OutputSection is no longer a template, it doesn't make much
sense to tempalte its factory class.

llvm-svn: 296308
2017-02-27 02:31:48 +00:00
Rui Ueyama 9d1bacb1b4 Remove useless template so that Out<ELFT> becomes just Out.
llvm-svn: 296307
2017-02-27 02:31:26 +00:00
Rafael Espindola 24e6f363c5 Merge OutputSectionBase and OutputSection. NFC.
Now that all special sections are SyntheticSections, we only need one
OutputSection class.

llvm-svn: 296127
2017-02-24 15:07:30 +00:00
Rafael Espindola 29c1afb880 Delete trivial setter.
llvm-svn: 296124
2017-02-24 14:34:12 +00:00
Rafael Espindola 40849419e2 Delete trivial getter.
llvm-svn: 296123
2017-02-24 14:28:00 +00:00
Rafael Espindola 774ea7d0a9 Make InputSection a class. NFC.
With the current design an InputSection is basically anything that
goes directly in a OutputSection. That includes plain input section
but also synthetic sections, so this should probably not be a
template.

llvm-svn: 295993
2017-02-23 16:49:07 +00:00
George Rimar 2146787609 [ELF] - Refactoring of LMA offset handling code. NFC.
Thanks to Rui Ueyama for suggestion.

llvm-svn: 295943
2017-02-23 07:57:55 +00:00
Rafael Espindola c404d50d7c Merge InputSectionData and InputSectionBase.
Now that InputSectionBase is not a template there is no reason to have
the two.

llvm-svn: 295924
2017-02-23 02:32:18 +00:00
Rafael Espindola b4c9b81aad Convert InputSectionBase to a class.
Removing this template is not a big win by itself, but opens the way
for removing more templates.

llvm-svn: 295923
2017-02-23 02:28:28 +00:00
Petr Hosek 5e51f7d24e [ELF] Insert linkerscript symbols directly into symbol table
This change exposes the symbol table insert method and uses it to
insert the linkerscript defined symbols directly into the symbol
table to avoid unnecessarily pulling the object out of an archive.

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

llvm-svn: 295780
2017-02-21 22:32:51 +00:00
George Rimar 78ef645f94 [ELF] - Do not segfault when using --gc-sections with linker script
Patch fixes PR32024.

Sections that were not marked as Live has null output section.
Previously we tried to access that field and segfaulted.

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

llvm-svn: 295727
2017-02-21 15:46:43 +00:00
George Rimar ae4761c186 [ELF] - Postpone evaluation of LMA offset.
Previously we evaluated the values of LMA incorrectly for next cases:

.text : AT(ADDR(.text) - 0xffffffff80000000) { ... }
.data : AT(ADDR(.data) - 0xffffffff80000000) { ... }
.init.begin : AT(ADDR(.init.begin) - 0xffffffff80000000) { ... }

Reason was that we evaluated offset when VA was not assigned. For case above
we ended up with 3 loads that has similar LMA and it was incorrect.
That is critical for linux kernel.

Patch updates the offset after VA calculation. That fixes the issue.

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

llvm-svn: 295722
2017-02-21 15:08:18 +00:00
George Rimar 2ee2d2dcb5 [ELF] - Improve diagnostic messages for move location counter errors.
Previously LLD would error out just "ld.lld: error: unable to move location counter backward"
What does not really reveal the place of issue,
Patch adds location to the output.

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

llvm-svn: 295720
2017-02-21 14:50:38 +00:00
George Rimar 60f1fe8438 [ELF] - Make ASSERT() return Dot instead of evaluated value.
Previously ASSERT we implemented returned expression value.
Ex:
. = ASSERT(0x100);
would set Dot value to 0x100

Form of assert when it is assigned to Dot was implemented for 
compatibility with very old GNU ld which required it.
Some scripts in the wild, including linux kernel scripts 
use such ASSERTs at the end for doing different checks.

Currently we fail with "unable to move location counter backward"
for such scripts. Patch changes ASSERT to return location counter 
value to fix that.

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

llvm-svn: 295703
2017-02-21 07:33:38 +00:00
Rafael Espindola 3773bcac55 Fix --print-gc-sections with linker scripts.
Before it would never print anything.

Thanks to George Rimar for pointing it out.

llvm-svn: 295485
2017-02-17 19:37:30 +00:00
George Rimar 647c1685b6 [ELF] - Move DependentSections vector from InputSection to InputSectionBase
I splitted it from D29273.
Since we plan to make relocatable sections as dependent for target ones for
--emit-relocs implementation, this change is required to support .eh_frame case.

EhInputSection inherets from InputSectionBase and not from InputSection.
So for case when it has relocation section, it should be able to access DependentSections
vector.

This case is real for Linux kernel.

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

llvm-svn: 295483
2017-02-17 19:34:05 +00:00
Rafael Espindola ecbfd871f9 Don't print DISCARD sections as gced.
This is a small difference I noticed to gold and bfd. When given
--print-gc-sections, we print sections a linkerscript marks
DISCARD. The other linkers don't.

llvm-svn: 295467
2017-02-17 17:35:07 +00:00
Rafael Espindola 679828ff92 Diagnose another case of the location counter moving backwards.
This case should be possible to handle, but it is hard:

* In order to create program headers correctly, we have to scan the
  sections in the order they are in the file.

* To find that order, we have to "execute" the linker script.

* The linker script can contain SIZEOF_HEADERS.

So to support this we have to start with a guess of how many headers
we need (3), run the linker script and try to create the program
headers. If it turns out we need more headers, we run the script again
with a larger SIZEOF_HEADERS.

Also, running the linker script depends on knowing the size of the
sections, so we have to finalize them. But creating the program
headers can change the value stored in some sections, so we have to
split size finalization and content finalization.

Looks like the last part is also needed for range extension thunks, so
we might support this at some point. For now just report an error
instead of producing broken files.

llvm-svn: 295458
2017-02-17 16:26:13 +00:00
Rafael Espindola 4cd7352c4f Reject moving the location counter backwards.
We were only checking when the assignment was inside a section.

llvm-svn: 295454
2017-02-17 16:01:51 +00:00
Rafael Espindola 8290274c13 Share more output section creation code.
We can do this now that the linker script and the writer agree on
which sections should be combined.

llvm-svn: 295341
2017-02-16 17:32:26 +00:00
George Rimar 505ac8dc41 [ELF] - Do not crash when discarding sections that are referenced by others.
SHF_LINK_ORDER sections adds special ordering requirements.
Such sections references other sections. Previously we would crash
if section that other were referenced to was discarded by script.

Patch fixes that by discarding all dependent sections in that case.
It supports chained dependencies, testcase is provided.

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

llvm-svn: 295332
2017-02-16 16:06:13 +00:00
Rafael Espindola 908a3d3420 Ignore relocation sections in linker scripts.
Unfortunately, the common way of writing linker scripts seems to be
to get the output of ld.bfd --verbose and edit it a bit.

Also unfortunately, the bfd default script contains things like

.rela.dyn : { *(... .rela.data ...) }

but bfd actually ignores that for -emit-relocs, so we have to do the
same.

llvm-svn: 295324
2017-02-16 14:36:09 +00:00
Rui Ueyama 731a66ae98 Apply different tokenization rules to linker script expressions.
The linker script lexer is context-sensitive. In the regular context,
arithmetic operator characters are regular characters, but in the
expression context, they are independent tokens. This afects how the
lexer tokenizes "3*4", for example. (This kind of expression is real;
the Linux kernel uses it.)

This patch defines function `maybeSplitExpr`. This function splits the
current token into multiple expression tokens if the lexer is in the
expression context.

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

llvm-svn: 295225
2017-02-15 19:58:17 +00:00
Rui Ueyama 794366a237 Rename ScriptParser.{cpp,h} -> ScriptLexer.{cpp,h}.
These files contain a lexer, so the new names are better.
The parser is in LinkerScript.{cpp,h}.

llvm-svn: 295022
2017-02-14 04:47:05 +00:00
Peter Collingbourne 904c5ed558 ELF: Read all dynamic lists specified on the command line.
We were previously only reading the last one.

Fixes PR31939 (which was likely the issue underlying
https://github.com/google/oss-fuzz/issues/295).

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

llvm-svn: 294977
2017-02-13 18:31:12 +00:00
Rafael Espindola ea590d91a0 Revert "Simplify symbol computation for non alloc sections."
This reverts commit r294346. Looks like it regressed the build of
magenta.

llvm-svn: 294460
2017-02-08 15:19:03 +00:00
George Rimar 4e01c3e8cd [ELF] - Linkerscript - fix handling of OUTPUT_ARCH command.
OUTPUT_ARCH command can contain architecture values separated with ":", like:
OUTPUT_ARCH(i386:x86-64)

We did not support that, because got 3 lexer tokens here after recent changes.

This trivial patch fixes the issue, now whole expression inside 
OUTPUT_ARCH is just ignored.

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

llvm-svn: 294432
2017-02-08 09:59:06 +00:00
Petr Hosek 165088aa5c [ELF] Handle output section alignment in linker scripts
LLD already parses ALIGN expression to specifiy alignment for output
sections in linker scripts but it never applies the alignment to the
output section. This change handles that.

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

llvm-svn: 294374
2017-02-07 23:42:31 +00:00
Rafael Espindola 193b158b39 Simplify symbol computation for non alloc sections.
We now just keep the address the section would have if it was
allocatable. Only the writer ignores it at the very end.

llvm-svn: 294346
2017-02-07 20:22:04 +00:00
Dmitry Mikulin f3965c0246 Handle the case where 'local' is the name of a global in a version script:
{ global : local; local: *; };

llvm-svn: 294343
2017-02-07 19:50:47 +00:00
George Rimar c6cf1f1f02 [ELF] - Assign proper values for DefinedSynthetic symbols attached to non-allocatable sections.
DefinedSynthetic symbols are attached to sections,
for the case when such symbol was attached to non-allocated section,
we calculated its value incorrectly.

We subtracted Body->Section->Addr, but non-allocatable sections
should have zero VA in output and therefore result value was wrong.

And at the same time we have Body->Section->Addr != 0 for them 
internally because  use it for calculation of section size.

Patch fixes calculation of such symbols values.

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

llvm-svn: 294322
2017-02-07 17:51:35 +00:00
George Rimar b2b70975e0 [ELF] - Refactoring: reuse similar method.
We had assignSymbol and assignSectionSymbol methods which has similar functionality.
Patch removes one of copy and reuses another in code.

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

llvm-svn: 294290
2017-02-07 10:23:28 +00:00
Rafael Espindola 06f4743a48 Handle symbol assignments before the first section switch.
We now create a dummy section with index 1 before processing the
linker script.

Thanks to George Rimar for finding the bug and providing the initial
testcase.

llvm-svn: 294252
2017-02-06 22:21:46 +00:00
Rafael Espindola 2b07455315 Simplify. NFC.
Now that each OutputSectionCommand maps to just one OutputSection, we
can remove a few std::vectors.

llvm-svn: 294060
2017-02-03 22:27:05 +00:00
Rafael Espindola 4524268c02 Handle numbers followed by ":" in linker scripts.
This is a fix for Bugzilla 31813.

The problem is that the tokenizer does not create a separate token for
":" unless there's white space before it. Changed it to always create
a token for ":" and reworked some logic that relied on ":" being
attached to some tokens like "global:" and "local:".

llvm-svn: 294006
2017-02-03 13:24:01 +00:00
Rui Ueyama 6697ec293c Update comments.
llvm-svn: 293963
2017-02-02 23:26:12 +00:00
George Rimar 697507556a [ELF] - Recommit r293749. Improve comment. NFC.
llvm-svn: 293751
2017-02-01 09:14:22 +00:00
George Rimar 091f9b35c7 [ELF] - Revert r293749
Accidentally lost the commit title and message,
will recommit.

llvm-svn: 293750
2017-02-01 09:12:29 +00:00
George Rimar f46e54f078 (no commit message)
llvm-svn: 293749
2017-02-01 09:05:45 +00:00
George Rimar cc4d3e5745 [ELF] - Linkerscript: properly mark minus expression with non-absolute flag
This is alternative to D28857 which was incorrect.

One of linux scripts contains:

vvar_start = . - 2 * (1 << 12);
vvar_page = vvar_start;
vvar_vsyscall_gtod_data = vvar_page + 128;
Previously we did not mark first expression as non-absolute,
though it contains location counter.

And LLD failed with error:
relocation R_X86_64_PC32 cannot refer to absolute symbol

This patch should fix the issue, and opens road for doing the same for other operators
(though not clear if that is needed).

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

llvm-svn: 293748
2017-02-01 09:01:16 +00:00
George Rimar 2fe079233b [ELF] - Linkerscript: do not fail on additional semicolons in linkerscript.
Linux kernel linkerscript contains additional semicolon (last line):

.apicdrivers : AT(ADDR(.apicdrivers) - LOAD_OFFSET) {
  __apicdrivers = .;
  *(.apicdrivers);

I checked that both gold and bfd are able to parse something like:

.text : { ;;*(.text);;S = 0;; } }

Patch do the same.

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

llvm-svn: 293612
2017-01-31 08:50:11 +00:00
Rafael Espindola fe12450e8e Revert commits r293276 and r293278.
[ELF] Fixed formatting. NFC

and

    [ELF] Bypass section type check

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

They do the opposite of what was asked for in the code review.

llvm-svn: 293320
2017-01-27 18:39:30 +00:00
Eugene Leviant 8b7cadcf96 [ELF] Bypass section type check
Differential revision: https://reviews.llvm.org/D28761

llvm-svn: 293276
2017-01-27 11:01:43 +00:00
Rui Ueyama 8a8a953e99 Rename NotFlags -> NegFlags.
Negative flags are still bit flags, so I think "not flag" is a very good name.

llvm-svn: 293143
2017-01-26 02:58:59 +00:00
Rui Ueyama 481ac9967b Use StringRef::lower only once instead of calling ::tolower many times.
llvm-svn: 293142
2017-01-26 02:58:39 +00:00
Rui Ueyama 24e626cc76 Split ScriptParser::readMemory.
llvm-svn: 293141
2017-01-26 02:58:19 +00:00
Meador Inge b889744e5b [LinkerScript] Implement `MEMORY` command
As specified here:

* https://sourceware.org/binutils/docs/ld/MEMORY.html#MEMORY

There are two deviations from what is specified for GNU ld:

  1. Only integer constants and *not* constant expressions
     are allowed in `LENGTH` and `ORIGIN` initializations.

  2. The `I` and `L` attributes are *not* implemented.

With (1) there is currently no easy way to evaluate integer
only constant expressions.  This can be enhanced in the
future.

With (2) it isn't clear how these flags map to the `SHF_*`
flags or if they even make sense for an ELF linker.

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

llvm-svn: 292875
2017-01-24 02:34:00 +00:00
George Rimar 8e2eca229e [ELF] - Linkerscripts: ignore CONSTRUCTORS in output section declaration.
It is used in linux kernel script:
http://lxr.free-electrons.com/source/arch/x86/kernel/vmlinux.lds.S#L140

Though CONSTRUCTORS is ignored for ELF.

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

llvm-svn: 292777
2017-01-23 09:36:19 +00:00
Rafael Espindola 8c495e20bd Reduce code duplication when allocating program headers.
This will simplify a bug fix.

llvm-svn: 292642
2017-01-20 20:41:18 +00:00
George Rimar 60aed44387 [ELF] - Do not crash when assign common symbol's values in script
Found that during attempts of linking linux kernel,
previously we partially duplicated code from getOutputSection(),
and it missed commons symbol case.

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

llvm-svn: 292594
2017-01-20 09:45:36 +00:00
George Rimar 7185a1acec [ELF] - Support optional comma after output section command.
I found this when tried to link linux kernel with LLD:

https://github.com/torvalds/linux/blob/master/arch/x86/entry/vdso/vdso-layout.lds.S#L86

Output section command can have optional comma at the end:

.text		: { *(.text*) }			:text	=0x90909090,

It was documented about 3 years ago for binutils:
https://sourceware.org/ml/binutils/2014-04/msg00045.html

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

llvm-svn: 292225
2017-01-17 15:32:12 +00:00
Rafael Espindola e999ddb8de Add support for anonymous local symbols.
This actually simplifies the code a bit as now all local symbols are
handled uniformly.

This should fix the build of www/webkit2-gtk3.

llvm-svn: 291569
2017-01-10 16:37:24 +00:00
Meador Inge 8f1f3c40f6 [ELF] Allow defined symbols to be assigned from linker script
This patch allows for linker scripts to assign a new value
to a symbol that is already defined (either in an object file
or the linker script itself).

llvm-svn: 291459
2017-01-09 18:36:57 +00:00
Rui Ueyama ec1c75e059 Add linker-script-included files to reproduce tar files.
Previously, files added using INCLUDE directive weren't added
to reproduce archives. In this patch, I defined a function to
open a file and use that from Driver and LinkerScript.

llvm-svn: 291413
2017-01-09 01:42:02 +00:00
Rafael Espindola 337139830e Change which input sections we concatenate
After Mark's patch I was wondering what was the rationale for the ELF
spec requiring us to merge only sections with matching flags and
types. I tried emailing
https://groups.google.com/forum/#!forum/generic-abi, but looks like my
emails are not being posted (the list is probably moderated). I
emailed Cary Coutant instead.

Cary pointed out that the section was a late addition and didn't got
the scrutiny it deserved. Given that and the problems found by
implementing the letter of the standard, I propose changing lld to
merge all sections with the same name and issue errors if the types or
some critical flags are different.

This should allow an unmodified firefox linked with lld to run.

This also merges some code with the linkerscript path.

llvm-svn: 291107
2017-01-05 14:20:35 +00:00
Rui Ueyama 58841b45d0 Remove Driver::OwningMB and instead use make().
We managed new MemoryBuffers in different ways in LinkerScript.cpp and
Driver.cpp. With this patch, they are managed in the same way.

llvm-svn: 290411
2016-12-23 03:19:09 +00:00
Eugene Leviant f6aeed3624 [ELF] Linkerscript: print location of undefined symbol usage
Differential revision: https://reviews.llvm.org/D27194

llvm-svn: 290339
2016-12-22 13:13:12 +00:00
George Rimar d450065308 [ELF] - Linkerscript: Fall back to search paths when INCLUDE not found
From https://sourceware.org/binutils/docs/ld/File-Commands.html:
The file will be searched for in the current directory, and in any 
directory specified with the -L option.

Patch done by Alexander Richardson.

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

llvm-svn: 290247
2016-12-21 09:42:25 +00:00
Rui Ueyama 4f2f50dc64 De-template DefinedSynthetic.
DefinedSynthetic is not created for a real ELF object, so it doesn't
have to be a template function. It has a virtual st_value, which is
either 32 bit or 64 bit, but we can simply use 64 bit.

llvm-svn: 290241
2016-12-21 08:40:09 +00:00
George Rimar 4fb6e79c65 [ELF] - Fix use of freed memory.
It was revealed by D27831.

If we have linkerscript that includes another one that sets OUTPUT for example:

RUN: echo "INCLUDE \"foo.script\"" > %t.script
RUN: echo "OUTPUT(\"%t.out\")" > %T/foo.script
then we do:

void ScriptParser::readInclude() {
...
  std::unique_ptr<MemoryBuffer> &MB = *MBOrErr;
  tokenize(MB->getMemBufferRef());
  OwningMBs.push_back(std::move(MB));
}

void ScriptParser::readOutput() {
...
    Config->OutputFile = unquote(Tok);
...
}
Problem is that OwningMBs are destroyed after script parser do its job.
So all Toks are dead and Config->OutputFile points to destroyed data.

Patch suggests to save all included scripts into using string Saver.

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

llvm-svn: 290238
2016-12-21 08:11:49 +00:00
Rafael Espindola 5967c97323 Fix corner cases of setting the section address.
This handles all the corner cases if setting a section address:

- If the address is too low, we cannot allocate the program headers.
- If the load address is lowered, we have to do that before finalize

This also shares some code with the linker script since it was already
hitting similar cases.

This is used by the freebsd boot loader. It is not clear if we need to
support this with a non binary output, but it is not as bad as I was
expecting.

llvm-svn: 290136
2016-12-19 21:21:07 +00:00
Rafael Espindola 17cb7c0a2a Detemplate PhdrEntry. NFC.
llvm-svn: 290115
2016-12-19 17:01:01 +00:00
Rui Ueyama 9381eb1045 Remove lld/Support/Memory.h.
I thought for a while about how to remove it, but it looks like we
can just copy the file for now. Of course I'm not happy about that,
but it's just less than 50 lines of code, and we already have
duplicate code in Error.h and some other places. I want to solve
them all at once later.

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

llvm-svn: 290062
2016-12-18 14:06:06 +00:00
Rui Ueyama 5d804dc8f7 [ELF] - Linkerscript: Implement two argument version of ALIGN()
Fixes http://llvm.org/PR31129

Patch by Alexander Richardson!

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

llvm-svn: 289968
2016-12-16 18:19:35 +00:00
George Rimar 93c64025fc [ELF] - Apply format. NFC.
llvm-svn: 289823
2016-12-15 15:38:09 +00:00
George Rimar 14460e0216 [ELF] - Do not crash when move location counter backward.
PR31335 shows that we do that in next case:
SECTIONS { .text 0x2000 : {. = 0x100 ; *(.text) } }

though documentations says that "If . is used inside a section 
description however, it refers to the byte offset from the start
of that section, not an absolute address. " looks does not work 
as documented in bfd (as mentioned in comments for PR31335).

Until we find out the expected behavior was suggested at least not
to 'crash', what we do after trying to generate huge file.

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

llvm-svn: 289782
2016-12-15 07:27:28 +00:00
Rafael Espindola 1ef90d2f25 Fix parsing when one extern follows another.
llvm-svn: 289224
2016-12-09 16:44:05 +00:00
Meador Inge 95c7d8d2a7 [ELF] Allow output section data commands to take expressions
The current implementation of the output section data store commands
can only handle integer literals, but it should really handle arbitrary
expressions [1].  This commit fixes that.

[1] https://sourceware.org/binutils/docs-2.27/ld/Output-Section-Data.html#Output-Section-Data

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

llvm-svn: 289152
2016-12-08 23:21:30 +00:00
Rui Ueyama 520d9169e6 Move Memory.{h,cpp} to lld/Support so that we can use them from COFF.
llvm-svn: 289084
2016-12-08 18:31:13 +00:00
Rafael Espindola d0ebd84c42 Change the implementation of --dynamic-list to use linker script parsing.
The feature is documented as
-----------------------------
The format of the dynamic list is the same as the version node
without scope and node name.  See *note VERSION:: for more
information.
--------------------------------

And indeed qt uses a dynamic list with an 'extern "C++"' in it. With
this patch we support that

The change to gc-sections-shared makes us match bfd. Just because we
kept bar doesn't mean it has to be in the dynamic symbol table.

The changes to invalid-dynamic-list.test and reproduce.s are because
of the new parser.

The changes to version-script.s are the only case where we change
behavior with regards to bfd, but I would like to see a mix of
--version-script and --dynamic-list used in the wild before
complicating the code.

llvm-svn: 289082
2016-12-08 17:54:26 +00:00
Rafael Espindola 7e71415cb3 Add support for 'extern "C"'.
It is used by Qt.

llvm-svn: 289074
2016-12-08 17:26:53 +00:00
Rafael Espindola 41217616a8 Delete dead code.
Thanks to George Rimar for pointing it out.

llvm-svn: 289020
2016-12-08 03:17:05 +00:00
George Rimar a2a32c2cc8 [ELF] - Teach LLD to recognize PT_OPENBSD_BOOTDATA
Minor patch to fix PR31288

OpenBSD commit:
d39116912b

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

llvm-svn: 288832
2016-12-06 17:57:42 +00:00
Eugene Leviant 2a942c4b45 [ELF] Print file:line for unknown PHDR error
Differential revision: https://reviews.llvm.org/D27335

llvm-svn: 288678
2016-12-05 16:38:32 +00:00
Rui Ueyama b5f1c3ec0c Make get{Line,Column}Number members of StringParser.
This patch also renames currentLocation getCurrentLocation.

llvm-svn: 288308
2016-12-01 04:36:49 +00:00
George Rimar 3fb5a6dc9e [ELF] - Add support of proccessing of the rest allocatable synthetic sections from linkerscript.
This change continues what was started by D27040
Now all allocatable synthetics should be available from script side.

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

llvm-svn: 288150
2016-11-29 16:05:27 +00:00
George Rimar 18a3096282 [ELF] - Set Config->SingleRoRx differently. NFC.
Previously Config->SingleRoRx was set in
createFiles() and used HasSections.

This change moves it to readConfigs at place of
common flags handling, and adds logic that sets
this flag separatelly from ScriptParser if SECTIONS present.

llvm-svn: 288021
2016-11-28 10:11:10 +00:00
Eugene Leviant ed30ce7ae4 [ELF] Print file:line for 'undefined section' errors
Differential revision: https://reviews.llvm.org/D27108

llvm-svn: 288019
2016-11-28 09:58:04 +00:00
Rafael Espindola 5fcc99c27d Also skip regular symbol assignment at the start of a script.
Unfortunatelly some scripts look like

kernphys = ...
. = ....

and the expectation in that every orphan section is after the
assignment.

llvm-svn: 287996
2016-11-27 09:44:45 +00:00
Rafael Espindola 7fe4ec9b3a Don't put an orphan before the first . assignment.
This is an horrible special case, but seems to match bfd's behaviour
and is important for avoiding placing an orphan section before the
expected start of the file.

llvm-svn: 287994
2016-11-27 07:39:45 +00:00
Rafael Espindola f93b8c29c8 Create sections with just assignments as STT_NOBITS.
This matches the behaviour of bfd ld. Using 0 was causing problems
with strip, which would remove these sections.

llvm-svn: 287969
2016-11-26 06:55:35 +00:00
Rui Ueyama 22375f2406 Remove a parameter from ScriptParser.
llvm-svn: 287944
2016-11-25 18:51:54 +00:00
Rui Ueyama f373dd76ce Remove HasError and use ErrorCount instead.
HasError was always true if ErrorCount > 0, so we can use ErrorCount instead.

llvm-svn: 287849
2016-11-24 01:43:21 +00:00
Meador Inge b2d99d6a0f [ELF] Allow `ASSERT` in output section descriptions
GNU LD allows `ASSERT` commands to be in output section descriptions.
Note that LD also mandates that `ASSERT` commands in this context must
end with a semicolon.

llvm-svn: 287677
2016-11-22 18:01:50 +00:00
Rafael Espindola 28d5f059ae Use the correct page size.
Config->MaxPageSize is what we use for the segment alignment, so that
is the one that we have to use for placing the header.

llvm-svn: 287569
2016-11-21 20:20:04 +00:00
Rafael Espindola 1c57007ec8 Fix address computation for headers.
If the linker script has SECTIONS, the address computation is now
always done in LinkerScript::assignAddresses, like for any other
section.

Before fixHeaders would do a tentative computation that
assignAddresses would sometimes override.

This patch also splits the cases where assignAddresses needs to add
the headers to the first PT_LOAD and the address computation. The net
effect is that we no longer create an empty page for no reason in the
included test case, which matches bfd behavior.

llvm-svn: 287565
2016-11-21 19:59:33 +00:00
Eugene Leviant 03ff016666 [ELF] Better error reporting for linker scripts
Differential revision: https://reviews.llvm.org/D26795

llvm-svn: 287547
2016-11-21 15:49:56 +00:00
Rui Ueyama 0b1b695a9e Add comments.
This patch rearranges code a bit to make it easy to explain.

llvm-svn: 287515
2016-11-21 02:11:05 +00:00
Rui Ueyama e0be2901cd Simplify. NFC.
llvm-svn: 287514
2016-11-21 02:10:12 +00:00
Rui Ueyama f94efdddc0 Add a flag to InputSectionBase for linker script.
Previously, we set (uintptr_t)-1 to InputSectionBase::OutSec to record
that a section has already been set to be assigned to some output section
by linker scripts. Later, we restored nullptr to the pointer to use
the field for the original purpose. That overloading is not very easy to
understand.

This patch adds a bit flag for that purpose, so that we don't need
to piggyback the flag on an unrelated pointer.

llvm-svn: 287508
2016-11-20 23:15:52 +00:00
Rui Ueyama 061f9286df Use Optional<std::string> instead of "" to represent a failure.
llvm-svn: 287456
2016-11-19 19:23:58 +00:00
Rui Ueyama 6e68c5e5cf Simplify. NFC.
llvm-svn: 287446
2016-11-19 18:05:58 +00:00
Rui Ueyama 16068aeb58 Change filler type from ArrayRef<uint8_t> to uint32_t.
Filler expressions in linker script "=fillexp" are always handled
as 32-bit integers. Thus the new type is more natural.

llvm-svn: 287445
2016-11-19 18:05:56 +00:00
Rui Ueyama f8f6f1e783 Update comment.
llvm-svn: 287325
2016-11-18 07:03:56 +00:00
Rui Ueyama 009d174229 Omit empty parameter list.
llvm-svn: 287324
2016-11-18 06:49:09 +00:00
Rui Ueyama 46247b85be Use consume() instead of peek() and skip().
llvm-svn: 287323
2016-11-18 06:49:07 +00:00
Rui Ueyama 12450b20b4 Split ScriptParser::readVersionDeclaration.
readVersionDeclaration was to read anonymous version definition and
named version definition. Splitting it into two functions should
improve readability as the two cases are different enough.

I also changed a few helper functions to return values instead of
mutating given references.

llvm-svn: 287319
2016-11-18 06:30:09 +00:00
Rui Ueyama edf75e7992 Allow SIZEOF() command on nonexistent section.
Linker script doesn't create a section if it has no content. So the following
script doesn't create .norelocs section if it doesn't have any .rel* sections.

  .norelocs : { *(.rel*) }

Later, if you assert that the size of .norelocs is 0, LLD printed out
an error message, because it didn't allow calling SIZEOF() on nonexistent
sections.

This patch allows SIZEOF() on nonexistent sections, so that you can do
something like this.

  ASSERT(SIZEOF(.norelocs), "shouldn't contain .rel sections!")

Note that this behavior is compatible with GNU.

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

llvm-svn: 287257
2016-11-17 20:27:10 +00:00
Rafael Espindola d8b81d6663 Avoid accessing an end() iterator.
llvm-svn: 287225
2016-11-17 14:18:08 +00:00
Rui Ueyama 0ee25a6973 Simplify and use consistent variable name. NFC.
llvm-svn: 287200
2016-11-17 03:52:14 +00:00
Rui Ueyama da805c4800 Use uint16_t instead of size_t for symbol version ID.
Because it is uint16_t in the ELF spec. Using size_t was confusing.

llvm-svn: 287198
2016-11-17 03:39:21 +00:00
George Rimar 17c65af82f [ELF] - Separate locals list from versions.
This change separates all versioned locals to be a separate list in config,
that was suggested by Rafael and simplifies the logic a bit.

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

llvm-svn: 287132
2016-11-16 18:46:23 +00:00
George Rimar e0fc24210d [ELF] - Added support for extern "c++" local symbols in version script.
Previously we did not support them,
patch implements this functionality

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

llvm-svn: 287124
2016-11-16 17:59:10 +00:00
Eugene Leviant afaa934304 [ELF] Add Section() to expression object
This allows making symbols containing ADDR(section) synthetic,
and defining synthetic symbols outside SECTIONS block.

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

llvm-svn: 287090
2016-11-16 09:49:39 +00:00
Rui Ueyama 2a00b8461c Rename function to avoid function overloading.
We had two functions with the same name to read completely different
things. That was confusing.

llvm-svn: 286991
2016-11-15 17:51:07 +00:00
George Rimar 463984d4bf [ELF] - Better diagnostic for relative relocation to an absolute value error.
Patch adds a filename to that error message.

I faced next error when debugged one of FreeBSD port:
error: relocation R_X86_64_PLT32 cannot refer to absolute symbol __tls_get_addr

error message was poor and this patch improves it to show the locations 
of symbol declaration and using.

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

llvm-svn: 286940
2016-11-15 08:07:14 +00:00
Rafael Espindola f7a1744803 Fix program header propagation.
Propagate program headers by walking the commands, not the
sections. This allows us to propagate program headers even from
sections that don't end up in the output.

Fixes pr30997.

llvm-svn: 286837
2016-11-14 15:39:38 +00:00
Rafael Espindola 6a53737c92 Delay removing empty section commands. NFC.
To fix pr30997 we will have to keep them a bit longer, this just
splits that part of the diff.

llvm-svn: 286827
2016-11-14 14:33:49 +00:00
Rafael Espindola 07fe612973 Factor out removeEmptyCommands. NFC.
llvm-svn: 286826
2016-11-14 14:23:35 +00:00
Rafael Espindola 337f903c6c Factor out placeOrphanSections. NFC.
llvm-svn: 286824
2016-11-14 14:13:32 +00:00
George Rimar 59d9b4b4bc [ELF] - Removed trailing whitespace. NFC.
llvm-svn: 286803
2016-11-14 10:04:45 +00:00
George Rimar da841c161d [ELF] - Removed unused code. NFC.
This branch was unused I believe,
as Tok can never be empty.

llvm-svn: 286802
2016-11-14 10:03:54 +00:00
George Rimar bb6c01e7c3 [ELF] - Add support for locals list in version script.
Previously we did not support anything except "local: *", patch changes that.

Actually GNU rules of proccessing wildcards are more complex than that (http://www.airs.com/blog/archives/300):
There are 2 iteration for wildcards, at first iteration "*" wildcards are ignored and handled at second iteration.

Since we previously decided not to implement such complex rules,
I suggest solution that is implemented in this patch. So for "local: *" case nothing changes,
but if we have wildcarded locals,
they are processed before wildcarded globals. 

This should fix several FreeBSD ports, one of them is jpeg-turbo-1.5.1 and
currently blocks about 5k of ports.

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

llvm-svn: 286713
2016-11-12 07:04:15 +00:00
Rui Ueyama 1bdaf3e30c Remove an overloaded function to simplify.
This version of addRegular is almost identical to the other except
it lacked "size" parameter.

llvm-svn: 286416
2016-11-09 23:37:40 +00:00
Rafael Espindola e08e78df6d Make OutputSectionBase a class instead of class template.
The disadvantage is that we use uint64_t instad of uint32_t for some
value in 32 bit files. The advantage is a substantially simpler code,
faster builds and less code duplication.

llvm-svn: 286414
2016-11-09 23:23:45 +00:00
Rafael Espindola 04a2e348bb Split Header into individual fields.
This is similar to what was done for InputSection.

With this the various fields are stored in host order and only
converted to target order when writing.

llvm-svn: 286327
2016-11-09 01:42:41 +00:00
Rafael Espindola 8f9026baff Don't add null and discarded sections to the global list.
Avoids having to skip them multiple times.

llvm-svn: 286261
2016-11-08 18:23:02 +00:00
Rui Ueyama e8a6102fa9 Rewrite CommonInputSection as a synthetic input section.
A CommonInputSection is a section containing all common symbols.
That was an input section but was abstracted in a different way
than the synthetic input sections because it was written before
the synthetic input section was invented.

This patch rewrites CommonInputSection as a synthetic input section
so that it behaves better with other sections.

llvm-svn: 286053
2016-11-05 23:05:47 +00:00
Rui Ueyama 8c6a5aaf15 Create a vector containing all input sections.
Previously, we do this piece of code to iterate over all input sections.

  for (elf::ObjectFile<ELFT> *F : Symtab.getObjectFiles())
    for (InputSectionBase<ELFT> *S : F->getSections())

It turned out that this mechanisms doesn't work well with synthetic
input sections because synthetic input sections don't belong to any
input file.

This patch defines a vector that contains all input sections including
synthetic ones.

llvm-svn: 286051
2016-11-05 22:37:59 +00:00
Eugene Zelenko 22886a2853 Fix some Clang-tidy modernize-use-default and Include What You Use warnings; other minor fixes.
Differential revision: https://reviews.llvm.org/D26320

llvm-svn: 286030
2016-11-05 01:00:56 +00:00
Rui Ueyama f91282e1cf Add [<chars>] to the glob matcher to eliminate use of llvm::Regex.
Previously, it didn't support the character class, so we couldn't
eliminate the use fo llvm::Regex. Now that it is supported, we
can remove compileGlobPattern, which converts a glob pattern to
a regex.

This patch contains optimization for exact/prefix/suffix matches.

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

llvm-svn: 285949
2016-11-03 17:57:38 +00:00
Eugene Leviant db68845485 Use globMatch() instead of llvm::regex in linker scripts
This can speed up lld up to 5 times when linking applications 
with large number of sections and using linker script.

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

llvm-svn: 285895
2016-11-03 10:54:58 +00:00
Rui Ueyama 95642b95bd Remove Out::Pool and use make() instead.
llvm-svn: 285763
2016-11-01 23:09:07 +00:00
Rafael Espindola c96da1100d Remove second argument to readProvideOrAssignment.
With this expressions alone track if they are absolute or not.

llvm-svn: 285687
2016-11-01 11:30:45 +00:00
Rafael Espindola b0de56b59d The expr '.' is not absolute.
With this patch we keep track of the fact that . is a position in the
file and therefore not absolute. This allow us to compute relative
relocations that involve symbol that are defined in linker scripts
with '.'.

This fixes https://llvm.org/bugs/show_bug.cgi?id=30406

There is still more work to track absoluteness over the various
expressions, but this should unblock linking the EFI bootloader.

llvm-svn: 285641
2016-10-31 21:36:23 +00:00
Rafael Espindola 2f831dcafd Delay computation of IsAbsolute.
We parse linker scripts very early, but whether an expression is
absolute or not can depend on a symbol defined in a .o. Given that, we
have to delay the computation of IsAbsolute. We can do that by storing
an AST when parsing or by also making IsAbsolute a function like we do
for the expression value. This patch implements the second option.

llvm-svn: 285628
2016-10-31 19:56:37 +00:00
Rafael Espindola 63b4a37ef5 Simple numeric constants are absolute.
llvm-svn: 285621
2016-10-31 18:56:02 +00:00
Rafael Espindola a0aaa8a0a3 Mark a few more expressions as absolute.
llvm-svn: 285611
2016-10-31 18:20:34 +00:00
Rafael Espindola f661393ad6 Move IsAbsolute from SymbolAssignment to Expr.
And as a token of the new feature, make ALIGNOF always absolute.

This is a step in making it possible to have non absolute symbols out
of output sections.

llvm-svn: 285608
2016-10-31 17:43:38 +00:00
Rafael Espindola 498ed714f8 Simplify. NFC.
No need to subtract then add Sec->getVA().

llvm-svn: 285580
2016-10-31 14:44:41 +00:00
Rafael Espindola 3dabfc6b0d Correctly merge visibility of linkerscript created symbols.
llvm-svn: 285567
2016-10-31 13:14:53 +00:00
Rui Ueyama 55518e7dd8 Consolidate BumpPtrAllocators.
Previously, we have a lot of BumpPtrAllocators, but all these
allocators virtually have the same lifetime because they are
not freed until the linker finishes its job. This patch aggregates
them into a single allocator.

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

llvm-svn: 285452
2016-10-28 20:57:25 +00:00
Rafael Espindola 093abab817 Don't create a dummy ELF to process a binary file.
Now that it is easy to create input section and symbols, this is
simple.

llvm-svn: 285322
2016-10-27 17:45:40 +00:00
Rafael Espindola 1854a8ebb8 Delete trivial getters. NFC.
llvm-svn: 285190
2016-10-26 12:36:56 +00:00
Rafael Espindola 0e090522c8 Read section headers upfront.
Instead of storing a pointer, store the members we need.

The reason for doing this is that it makes it far easier to create
synthetic sections. It also avoids reading data from files multiple
times., which might help with cross endian linking and host
architectures with slow unaligned access.

There are obvious compacting opportunities, but this already has mixed
results even on native x86_64 linking.

There is also the possibility of better refactoring the code for
handling common symbols, but this already shows that a custom class is
not necessary.

llvm-svn: 285148
2016-10-26 00:54:03 +00:00
Rafael Espindola 58139d1758 Delete getSectionHdr.
We were fairly inconsistent as to what information should be accessed
with getSectionHdr and what information (like alignment) was stored
elsewhere.

Now all section info has a dedicated getter. The code is also a bit
more compact.

llvm-svn: 285079
2016-10-25 16:14:25 +00:00
Eugene Leviant db35fdf70f Don't include PHDRs if linker script doesn't want them
This script below shouldn't include file and program headers
to PT_LOAD segment, because it doesn't have PHDRS and FILEHDR
attributes:

PHDRS { all PT_LOAD; }
SECTIONS { /* list of sections here */ }

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

llvm-svn: 284709
2016-10-20 09:39:09 +00:00
George Rimar a4c7e74d4b [ELF] - Applied clang format. NFC.
llvm-svn: 284705
2016-10-20 08:36:42 +00:00
Rui Ueyama 7c1381a099 Read an expression in the form of "ABSOLUTE(<expr>) op <expr> ...".
Fixes bug 30741.

llvm-svn: 284662
2016-10-19 23:11:21 +00:00
Eugene Leviant ce30b1c78e [ELF] Choose default segment when it is not specified
Linker scripts may specify PHDRS, but not specify section to
segment assignments, i.e:

PHDRS { seg PT_LOAD; }
SECTIONS { 
  .sec1 {} : seg
  .sec2 {} 
}

In such case linker should still choose some segment for .sec2 section.
This patch will add .sec2 to previously opened segments (seg) or to the 
very first PT_LOAD segment, if no section-to-segment assignments has been
made

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

llvm-svn: 284600
2016-10-19 15:04:49 +00:00
George Rimar 95dd718c98 [ELF] - Linkerscript: accept integer values for PHDRS types.
Both gold and ld accepts integers instead of named constants
for PHDRS.
Patch adds support for that.

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

llvm-svn: 284470
2016-10-18 10:49:50 +00:00
Rui Ueyama 83043f237c Rename skip(StringRef) -> consume(StringRef).
skip() and skip(StringRef) were overloaded functions that
have different semantics. This patch rename one of the functions
to avoid function overloading.

llvm-svn: 284396
2016-10-17 16:01:53 +00:00
Justin Bogner 5424e7c7dc ELF: Add a skip() overload to ignore any token
Most functions that return StringRef should check their return values,
so I'm planning on marking StringRef [[nodiscard]]. This requires
splitting up functions like next() that are sometimes just used for
side effects.

llvm-svn: 284363
2016-10-17 06:21:13 +00:00
Justin Bogner 5af1687fd2 ELF: Fix a misuse of Twine::toStringRef
While the toStringRef API almost certainly ends up populating the
SmallString here, the correct way to use this API is to use the return
value.

llvm-svn: 284361
2016-10-17 06:08:48 +00:00
George Rimar 270173f2db [ELF] - Added support of PT_OPENBSD_RANDOMIZE
This is 30646.

PT_OPENBSD_RANDOMIZE
The array element specifies the location and size of a part of the memory image of the program that must be filled with random data before any code in the object is executed. The memory region specified by a segment of this type may overlap the region specified by a PT_GNU_RELRO segment, in which case the intersection will be filled with random data before being marked read-only.

Reference links:
http://man.openbsd.org/OpenBSD-current/man5/elf.5
c494713c45

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

llvm-svn: 284234
2016-10-14 13:02:22 +00:00
George Rimar cc6e567ca3 [ELF] - Implemented -z wxneeded.
-z wxneeded creates a PHDR PT_OPENBSD_WXNEEDED.

PT_OPENBSD_WXNEEDED
The array element specifies that a process executing this file may need to be able to map or protect memory regions as simultaneously executable and writable. If the system is unable or unwilling to permit that for this executable then it may fail immediately. This segment type is meaningful only for executable files and is ignored in other objects.

http://man.openbsd.org/OpenBSD-current/man5/elf.5

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

llvm-svn: 284226
2016-10-14 10:34:36 +00:00
Rui Ueyama 05384080df Support GNU-style ZLIB-compressed input sections.
Previously, we supported only SHF_COMPRESSED sections because it's
new and it's the ELF standard. But there are object files compressed
in the GNU style out there, so we had to support it.

Sections compressed in the GNU style start with ".zdebug_" and
contain different headers than the ELF standard's one. In this
patch, getRawCompressedData is responsible to handle it.

A tricky thing about GNU-style compressed sections is that we have
to rename them when creating output sections. ".zdebug_" prefix
implies the section is compressed. We need to rename ".zdebug_"
".debug" because our output sections are not compressed.
We do that in this patch.

llvm-svn: 284068
2016-10-12 22:36:31 +00:00
Eugene Leviant cc1ba8c7d0 Alternative fix for reloc tareting discarded section
r283984 introduced a problem of too many warning messages being shown
when -ffunction-sections and -fdata-sections were used in conjunction 
with --gc-sections linker flag and debugging information present. This
happens because lot of relocations from .debug_line section may become
invalid in such case. The newer fix doesn't show any warning message but
zeroes OutSec pointer in createInputSectionList() to avoid crash, when
relocations are written

llvm-svn: 284010
2016-10-12 12:31:34 +00:00
Rui Ueyama b224c048b4 Remove trailing whitespace.
llvm-svn: 283786
2016-10-10 18:10:01 +00:00
Eugene Leviant cd8eaf891a [ELF] Don't emit empty PT_LOAD segment
Sometimes the very first PT_LOAD segment, created by lld, can be empty. 
This happens when (all conditions met):

- Linker script is used
- First section in ELF image is not RO
- Not enough space for program headers.

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

llvm-svn: 283760
2016-10-10 15:09:44 +00:00
Eugene Leviant 9257764d61 [ELF] Change argument type for findSections. NFC
llvm-svn: 283742
2016-10-10 11:23:12 +00:00
Eugene Leviant b71d6f7a72 [ELF] Linker script: implement LOADADDR
Differential revision: https://reviews.llvm.org/D24298

llvm-svn: 283429
2016-10-06 09:39:28 +00:00
Rui Ueyama b66260ac17 Remove trailing whitespace.
llvm-svn: 283372
2016-10-05 20:09:50 +00:00
Eugene Leviant a8d12ef853 Do not join sections for relocatable object files
Differential revision: https://reviews.llvm.org/D25232

llvm-svn: 283307
2016-10-05 10:10:45 +00:00
Eugene Leviant cf43f179b1 [ELF] make KEEP command recognize file patterns
Differential revision: https://reviews.llvm.org/D25242

llvm-svn: 283305
2016-10-05 09:36:59 +00:00
Rafael Espindola be6073345e Start linker scripts at 0.
We were implicitly creating space for the headers. That is not the
behaviour of bfd, which requires the script to use SIZEOF_HEADERS. The
difference is important for scripts that don't use SIZEOF_HEADERS and
expect the first section to be at 0.

llvm-svn: 282818
2016-09-30 00:16:11 +00:00
Rafael Espindola 6d91fce526 Don't error if we can't put the header in a PT_LOAD.
If there is not sufficient address space, just give up and don't put
the header in the PT_LOAD.

This matches bfd behaviour and I found at least one script that
depends on having a section at address 0.

llvm-svn: 282750
2016-09-29 18:50:34 +00:00
Petr Hosek 997f8838e5 [ELF] Support -z max-page-size option
This options issupported by both BFD ld and gold and allows
overriding the max page size whose default values are defined by
the target.

https://llvm.org/bugs/show_bug.cgi?id=30541

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

llvm-svn: 282596
2016-09-28 15:20:47 +00:00
George Rimar e38cbab5a4 [ELF] - Linkerscript: implemented BYTE/SHORT/LONG/QUAD commands.
The BYTE, SHORT, LONG, and QUAD commands store one, two, four, and eight bytes (respectively). 
After storing the bytes, the location counter is incremented by the number of bytes
stored.

Previously our scripts handles these commands incorrectly. For example:
SECTIONS  {
  .foo : {
 *(.foo.1)
 BYTE(0x11)
...
We accepted the script above treating BYTE as input section description. 
These commands are used in the wild though.

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

llvm-svn: 282429
2016-09-26 19:22:50 +00:00
George Rimar f28210285b [ELF] - Format. NFC.
llvm-svn: 282395
2016-09-26 11:00:48 +00:00
Rui Ueyama 9c4ac5f26c Combine two StringSwitch::Cases because Cases now can take 6 parameters.
llvm-svn: 282307
2016-09-23 22:22:34 +00:00
Rafael Espindola 65499b9040 Avoid counting sections twice.
We were counting the size of the bss section holding common symbols twice:

    Dot += CurOutSec->getSize();
    flush();

The new code is also simpler as now flush is the only function that
inserts in AlreadyOutputOS, which makes sense since the set hold fully
output sections.

llvm-svn: 282285
2016-09-23 20:10:47 +00:00
Rui Ueyama 0120e3f278 Simplify. NFC.
llvm-svn: 282268
2016-09-23 18:06:51 +00:00
George Rimar 4ebc562052 [ELF] - Linkerscript: accept space between '=' and expression in section filler.
Previously we failed to parse next scripts because disallowed
a space between filler value and '=':

  .text : {
...
  } :text = 0x9090

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

llvm-svn: 282248
2016-09-23 13:29:20 +00:00
George Rimar f34f45fd53 [ELF] - Linkerscript: implement DEFINED() command.
DEFINED(symbol)
Return 1 if symbol is in the linker global symbol table and is defined before
the statement using DEFINED in the script, otherwise return 0.

Can be used to define default values for symbols. Found it in the wild.

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

llvm-svn: 282245
2016-09-23 13:17:23 +00:00
George Rimar c8ccd1f1c5 [ELF] - Linkerscript: Implemented >> and <<
Found this operators used in the wild scripts, for example:

__got2_entries = (_FIXUP_TABLE_ - _GOT2_TABLE_) >>2;
__fixup_entries = (. - _FIXUP_TABLE_)>>2;

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

llvm-svn: 282243
2016-09-23 13:13:55 +00:00
Rafael Espindola 15c579518d Don't move orphan sections past assignments.
This fixes a case where we would produce an unaligned PT_LOAD.

llvm-svn: 282180
2016-09-22 18:05:49 +00:00
Rafael Espindola 1998ee53f0 Simplify. NFC.
With the recent changes there should always be a 1:1 correspondence in
the correct order between OutputSections and OutputSectionCommands.

llvm-svn: 282176
2016-09-22 17:23:53 +00:00
Rafael Espindola 0d4b6d5c98 Avoid duplicated code.
This also fixes the linker script accounting for the ELF header in
some places but not in others.

llvm-svn: 282173
2016-09-22 16:47:21 +00:00
Rafael Espindola 2644208381 Simplify. NFC.
It doesn't matter which direction we rotate and we haven't really
started optimizing the linker script code, so keep this simple.

llvm-svn: 282166
2016-09-22 15:25:21 +00:00
Rafael Espindola 9546fffbfe Handle empty sections with symbol assignments.
Before the symbols were becoming undefined.

llvm-svn: 282159
2016-09-22 14:40:50 +00:00
Rafael Espindola a940e5396b Fix VA computation for tbss.
llvm-svn: 282149
2016-09-22 12:35:44 +00:00
Rafael Espindola 7252ae52cf Handle multiple .tbss sections.
llvm-svn: 282147
2016-09-22 12:00:08 +00:00
Rafael Espindola e746e52c7b Implement ONLY_IF_RO/ONLY_IF_RW like bfd.
The actual logic is to keep the output section if the output section
would have been ro/rw.

This is both simpler and more practical, as the intention is linker
scripts is to always keep of of a pair of ONLY_IF_RO/ONLY_IF_RW.

llvm-svn: 282099
2016-09-21 18:33:44 +00:00
George Rimar 07171f21d1 [ELF] - Linkerscript: support complex section pattern grammar.
This is PR30442.
Previously we were failed to parce complex expressions like:
foo : { *(SORT_BY_NAME(bar) zed) }

Main idea of patch that globs and excludes can be wrapped in a SORT.
There is a difference in semanics of ld/gold:
ld likes:
*(SORT(EXCLUDE_FILE (*file1.o) .foo.1))

gold likes:
*(EXCLUDE_FILE (*file1.o) SORT(.foo.1))

Patch implements ld grammar, complex expressions like 
next is not a problem anymore:
.abc : { *(SORT(.foo.* EXCLUDE_FILE (*file1.o) .bar.*) .bar.*) }


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

llvm-svn: 282078
2016-09-21 15:56:44 +00:00
Eugene Leviant 2506cb4ddb Linker script: Fix bug with several .bss
When final image has several .bss sections, lld fails
because second .bss always has zero VA. This causes 
link error "Not enough space for ELF and program headers"

llvm-svn: 282067
2016-09-21 11:29:28 +00:00
George Rimar 601e989879 [ELF] - Linkerscript: reimplement readSectionExcludes()
It is not only a bit more straightforward now, but also next 2 issues are solved:

* It just crashed on ".foo : { *(EXCLUDE_FILE (*file1.o)) }" before.
* It accepted multiple EXCLUDE_FILEs in a row.

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

llvm-svn: 282060
2016-09-21 08:53:21 +00:00
Rafael Espindola b6b8f6c308 Revert "Revert "Only restrict order if both sections are in the script.""
This reverts commit r282021, bringing back r282015.

The problem was that the comparison function was not a strict weak
ordering anymore, which this patch fixes.

Original message:

Only restrict order if both sections are in the script.

This matches gold and bfd behavior and is required to handle some scripts.

The script has to assume where PT_LOADs start in order to align that
spot. If we don't allow section it doesn't know about to move to the
middle, we can need more PT_LOADs and those will not be aligned.

llvm-svn: 282035
2016-09-20 22:43:15 +00:00
Rafael Espindola bf04708e11 Revert "Only restrict order if both sections are in the script."
This reverts commit r282015. It broke some bots.

llvm-svn: 282021
2016-09-20 21:28:19 +00:00
Rafael Espindola 145569df64 Only restrict order if both sections are in the script.
This matches gold and bfd behavior and is required to handle some scripts.

The script has to assume where PT_LOADs start in order to align that
spot. If we don't allow section it doesn't know about to move to the
middle, we can need more PT_LOADs and those will not be aligned.

llvm-svn: 282015
2016-09-20 20:54:39 +00:00
Rui Ueyama ee92470969 Simplify SORT and --sort-section command line option handling.
Differential Revision: https://reviews.llvm.org/D24685

llvm-svn: 282006
2016-09-20 19:42:41 +00:00
Rafael Espindola 6d38e4dbe1 Remove empty section commands.
We were already not creating them, and with this other parts of the
code don't have to worry about them.

llvm-svn: 281968
2016-09-20 13:12:07 +00:00
Rafael Espindola f135f0ec1d Remove unnecessary const_canst. NFC.
llvm-svn: 281901
2016-09-19 13:33:38 +00:00
George Rimar b31dd37005 [ELF] - LinkerScript: Add workaround for gcc 6.2.0 failure w/auto
Will Dietz found and reported that lld does not compile with gcc 6.2.0,
more details https://llvm.org/bugs/show_bug.cgi?id=30438

And confirmed this change fixes the issue.

llvm-svn: 281900
2016-09-19 13:27:31 +00:00
George Rimar 194470cd11 [ELF] - Fix comment. NFC.
llvm-svn: 281836
2016-09-17 19:21:05 +00:00
George Rimar af03be19f9 [ELF] - Added comments. NFC.
llvm-svn: 281835
2016-09-17 19:17:25 +00:00
George Rimar 8c658bf824 [ELF] - SEGMENT_START's default argument can be an expression
Our implementation supported integer value previously.
ld can use expression,
for example, it is OK to write
 . = SEGMENT_START("foobar", .);

Patch implements that.

llvm-svn: 281831
2016-09-17 18:14:56 +00:00
George Rimar dfbbbc86a1 [ELF] Linkerscript: fixed bug about commands processing.
It was possible situation about some commands just were not processed
(were skipped) because of a bug appeared when constraint checking used.

Testcase is attached.

llvm-svn: 281818
2016-09-17 09:50:10 +00:00
Rui Ueyama 4dc07becd0 Use named struct instead of unnamed std::pair.
It is important to give members names for readability.

llvm-svn: 281803
2016-09-17 02:23:40 +00:00
Rui Ueyama 3ff27f49cd Define a versatile utility function and use it instead of a single purpose one.
llvm-svn: 281802
2016-09-17 02:15:28 +00:00
Rui Ueyama 027a9e8787 Remove unnecessary namespace specifiers.
llvm-svn: 281801
2016-09-17 02:10:15 +00:00
Rafael Espindola 373343bd5b Try to fix a few bots.
llvm-svn: 281794
2016-09-16 22:47:34 +00:00
Rafael Espindola aab6d5c52a Put SHF_ALLOC sections first, even with linker scripts.
This matches gold and bfd, and is pretty much required by some linker
scripts. They end with commands like

foo   0 : { *(bar) }

if we put any SHF_ALLOC sections after they can have an address that
is too low.

llvm-svn: 281778
2016-09-16 21:29:07 +00:00
Rui Ueyama b2a0abdf0e Rename SortSectionPolicy::IgnoreConfig to None.
Because it corresponds to SORT_NONE. None was renamed Default.

llvm-svn: 281776
2016-09-16 21:14:55 +00:00
Rafael Espindola 7c3ff2eb58 Only process commands in a ONLY_IF_RO if it matches.
This matches bfd behavior. It also makes future changes simpler as we
don't have to worry about ignoring these commands in multiple places

llvm-svn: 281775
2016-09-16 21:05:36 +00:00
Rafael Espindola e71a3f8ae1 Fix constraint checking in ONLY_IF_RO.
We have to look at all the relevant input sections at once.

llvm-svn: 281772
2016-09-16 20:34:02 +00:00
George Rimar be394db376 [ELF] - Implemented --sort-section cmd line option and SORT_NONE script command.
This fixes Bug 30385 - SORT_NONE not implemented,

`SORT_NONE' disables section sorting by ignoring the command line
section sorting option.

That is why this patch also implements --sort-section option.

Description of sorting rules
available at https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html 

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

llvm-svn: 281771
2016-09-16 20:21:55 +00:00
George Rimar 395281cfc3 Recommit r281721 "[ELF] - Linkerscript: implement EXCLUDE_FILE in the middle of a input section description."
With fix for 2 bots. Details about the fix performed is on a review page.

Initial commit message:
This is PR30387:

From PR description:
We fail to parse

SECTIONS
{
  foo :
  {
    *(sec0 EXCLUDE_FILE (zed1.o) sec1  EXCLUDE_FILE (zed2.o) sec2 )
  }
}
The semantics according to bfd are:

Include sec1 from every file but zed1.o
Include sec2 from every file but zed2.o
Include sec0 from every file

Patch implements the support.

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

llvm-svn: 281754
2016-09-16 17:42:10 +00:00
Eugene Leviant 20d031948e Improve handling ASSERT outside SECTIONS block
Differential revision: https://reviews.llvm.org/D24450

llvm-svn: 281740
2016-09-16 15:30:47 +00:00
Rafael Espindola d31907957a Change how we compute offsets with linker scripts.
This fixes pr30367, but more importantly, it changes how we compute offsets.

Now offset computation in a walk over linker script commands, like the
rest of assignAddresses. IMHO this is simpler to understand and if we
ever have to create multiple outputsections or chunks to change how we
handle test/ELF/linkerscript/alternate-sections.s it should be easier
to do it.

llvm-svn: 281736
2016-09-16 15:10:23 +00:00
George Rimar ceae630c9b Reverted r281721 ("[ELF] - Linkerscript: implement EXCLUDE_FILE in the middle of a input section description.").
It broke build bot:
http://lab.llvm.org:8011/builders/lld-x86_64-darwin13/builds/27508

llvm-svn: 281723
2016-09-16 13:30:18 +00:00
George Rimar 4906c7f5c4 [ELF] - Linkerscript: implement EXCLUDE_FILE in the middle of a input section description.
This is PR30387:

From PR description:
We fail to parse

SECTIONS
{
  foo :
  {
    *(sec0 EXCLUDE_FILE (zed1.o) sec1  EXCLUDE_FILE (zed2.o) sec2 )
  }
}
The semantics according to bfd are:

Include sec1 from every file but zed1.o
Include sec2 from every file but zed2.o
Include sec0 from every file

Patch implements the support.

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

llvm-svn: 281721
2016-09-16 13:07:02 +00:00
Rafael Espindola 4ec013ac83 Error out instead of producing a corrupt PT_LOAD.
What bfd and gold do is give up in putting the headers in the PT_LOAD
and just start the PT_LOAD in the second page.

llvm-svn: 281660
2016-09-15 21:22:11 +00:00
George Rimar 575208cabd [ELF] - Linkerscript: implemented SORT_BY_INIT_PRIORITY.
This is PR30386,

SORT_BY_INIT_PRIORITY is a keyword can be used to sort sections by numerical value of the
GCC init_priority attribute encoded in the section name.

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

llvm-svn: 281646
2016-09-15 19:15:12 +00:00
Rafael Espindola 3adbbc3891 Check the return of getInteger.
llvm-svn: 281608
2016-09-15 13:36:44 +00:00
Rafael Espindola 97bdc7220b Handle arbitrary expressions in DATA_SEGMENT_RELRO_END.
llvm-svn: 281521
2016-09-14 19:14:01 +00:00
Rafael Espindola be94e1b630 Move helper function higher in the file. NFC
This just makes a followup patch easier to read.

llvm-svn: 281482
2016-09-14 14:32:08 +00:00
Eugene Leviant e05336ffa1 [ELF] Replace HasContents with HasSections. NFC
llvm-svn: 281449
2016-09-14 08:32:36 +00:00