Commit Graph

429 Commits

Author SHA1 Message Date
Rafael Espindola ea2c78369c Reduce code duplication.
getVA was already implemented in the base class.

llvm-svn: 330036
2018-04-13 16:07:27 +00:00
Simon Atanasyan 1ba194212a [ELF][MIPS] Support linking of PIE for MIPS
MIPS ABI requires creation of the MIPS_RLD_MAP dynamic tag for non-PIE
executables only and MIPS_RLD_MAP_REL tag for both PIE and non-PIE
executables. The patch skips definition of the MIPS_RLD_MAP for PIE
files and defines MIPS_RLD_MAP_REL.

The MIPS_RLD_MAP_REL tag stores the offset to the .rld_map section
relative to the address of the tag itself.

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

llvm-svn: 329996
2018-04-13 08:15:01 +00:00
George Rimar c552619fc1 [ELF] - Reorder local symbols.
This fixes PR36716 (https://bugs.llvm.org/show_bug.cgi?id=36716),

Patch sorts local symbols to match the
following order: file1, local1, hidden1, file2, local2, hidden2 ...

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

llvm-svn: 329787
2018-04-11 09:24:27 +00:00
Rafael Espindola 9b6a65b144 Don't ignore addend when a SHF_MERGE section is dead.
This is similar to r329219, but for the entire section. Like r329219 I
don't expect this to have any real impact, it is just more consistent
and simpler.

llvm-svn: 329367
2018-04-06 01:10:33 +00:00
Rafael Espindola 7bd45502fe Initialize OffsetMap earlier.
Now that getSectionPiece uses OffsetMap, it is advantageous to
initialize it earlier.

llvm-svn: 329242
2018-04-05 00:01:57 +00:00
George Rimar 55d717805b [ELF] - Use early return. NFC.
llvm-svn: 329180
2018-04-04 12:36:21 +00:00
Rafael Espindola 6cd7af51e1 Inline initOffsetMap.
In the lld perf builder r328686 had a negative impact in
stalled-cycles-frontend. Somehow that stat is not showing on my
machine, but the attached patch shows an improvement on cache-misses,
which is probably a reasonable proxy.

My working theory is that given a large input the pieces vector is out
of cache by the time initOffsetMap runs.

Both finalizeContents implementation have a convenient location for
initializing the OffsetMap, so this seems the best solution.

llvm-svn: 329117
2018-04-03 21:38:18 +00:00
Peter Collingbourne c5391ce51e ELF: Allow thunks to change size. NFCI.
Differential Revision: https://reviews.llvm.org/D44962

llvm-svn: 328841
2018-03-29 22:32:13 +00:00
Peter Collingbourne cebab4a639 ELF: Make required Thunk methods pure virtual and remove an unused argument. NFC.
Also make certain Thunk methods non-const as this will be required for
an upcoming change.

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

llvm-svn: 328732
2018-03-28 21:33:31 +00:00
Rafael Espindola 816127ea17 Initialize OffsetMap in a known location.
This is a small optimization and avoids the need to use call_once.

llvm-svn: 328686
2018-03-28 03:20:18 +00:00
Zaara Syeda c65ae14766 [ELF] GotSection increment NumEntries when Target saves GlobalOffsetTable in the .got
When the target saves ElfSym::GlobalOffsetTable in the .got rather than
.got.plt, Target->GotHeaderEntriesNum states the number of extra entries
required in the .got. Rather than having to add Target->GotHeaderEntriesNum to
NumEntries in every function which refers to NumEntries, this patch changes the
initial value of NumEntries in the constructor.

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

llvm-svn: 328559
2018-03-26 17:50:52 +00:00
Rafael Espindola 4f058a2c6b Add a SectionBase::getVA helper. NFC.
There were a few too many places duplicating this.

llvm-svn: 328402
2018-03-24 00:35:11 +00:00
Rui Ueyama d37c33aff2 Do not add a dummy entry to SharedFile::Verdefs. NFC.
Previously, we used 0 as an alias for VER_NDX_GLOBAL and had a dummy
entry in SharedFile::Verdefs so that the access to the array is within
its boundary. But that's not straightforwad. We can just stop doing both.

llvm-svn: 328401
2018-03-24 00:25:24 +00:00
Eric Christopher 7baac21bce Fix consitent -> consistent.
llvm-svn: 328010
2018-03-20 18:10:30 +00:00
Rui Ueyama ba32e739b2 Remove GnuHashTableSection::getShift2().
Choosing a Shift2 value based on wordsize is cargo-culted from gold.
Assuming that djb hash is a good hash function, choosing bits [4,9]
shouldn't be any worse or better than choosing bits [5,10]. We shouldn't
have copied that behavior that we can't justify in the first place.

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

llvm-svn: 327921
2018-03-19 23:04:13 +00:00
Zaara Syeda 52ed6eb8d9 [ELF] Add basic support for PPC LE
This patch adds changes to start supporting the Power 64-Bit ELF V2 ABI.
This includes:
- Changing the ElfSym::GlobalOffsetTable to be named .TOC.
- Creating a GotHeader so the first entry in the .got is .TOC.
- Setting the e_flags to be 1 for ELF V1 and 2 for ELF V2

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

llvm-svn: 327871
2018-03-19 17:40:14 +00:00
Peter Smith 3d044f57d4 [ELF] Recommit 327248 with Arm using the .got for _GLOBAL_OFFSET_TABLE_
This is the same as 327248 except Arm defining _GLOBAL_OFFSET_TABLE_ to
be the base of the .got section as some existing code is relying upon it.

For most Targets the _GLOBAL_OFFSET_TABLE_ symbol is expected to be at
the start of the .got.plt section so that _GLOBAL_OFFSET_TABLE_[0] =
reserved value that is by convention the address of the dynamic section.
Previously we had defined _GLOBAL_OFFSET_TABLE_ as either the start or end
of the .got section with the intention that the .got.plt section would
follow the .got. However this does not always hold with the current
default section ordering so _GLOBAL_OFFSET_TABLE_[0] may not be consistent
with the reserved first entry of the .got.plt.

X86, X86_64 and AArch64 will use the .got.plt. Arm, Mips and Power use .got

Fixes PR36555

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

llvm-svn: 327823
2018-03-19 06:52:51 +00:00
Peter Collingbourne 5c902845e5 Revert r327248, "For most Targets the _GLOBAL_OFFSET_TABLE_ symbol is expected to be at"
This change broke ARM code that expects to be able to add
_GLOBAL_OFFSET_TABLE_ to the result of an R_ARM_REL32.

I will provide a reproducer on llvm-commits.

llvm-svn: 327688
2018-03-16 01:01:44 +00:00
Rui Ueyama 4e6b822cdc Separate sentences to clarify a comment.
llvm-svn: 327555
2018-03-14 19:01:00 +00:00
George Rimar 2ab9362bf5 [ELF] - Never create .gnu_hash with NBuckets == 0.
Currently, we can end up with NBuckets==0 and android loader
does not like it (PR36537).

Seems we can go with a minimal amount of changes here for simplicity
and be consistent with gold and so just always use >= 1 value for NBuckets.

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

llvm-svn: 327481
2018-03-14 08:52:39 +00:00
Peter Smith 18aa0be36e For most Targets the _GLOBAL_OFFSET_TABLE_ symbol is expected to be at
the start of the .got.plt section so that _GLOBAL_OFFSET_TABLE_[0] =
reserved value that is by convention the address of the dynamic section.
Previously we had defined _GLOBAL_OFFSET_TABLE_ as either the start or end
of the .got section with the intention that the .got.plt section would
follow the .got. However this does not always hold with the current
default section ordering so _GLOBAL_OFFSET_TABLE_[0] may not be consistent
with the reserved first entry of the .got.plt.

X86, X86_64, Arm and AArch64 will use the .got.plt. Mips and Power use .got

Fixes PR36555

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

llvm-svn: 327248
2018-03-11 20:58:18 +00:00
Fangrui Song 0c483024e4 [ELF] Convert {read,write}*be to endianness-aware read/write.
Subscribers: emaste, nemanjai, arichardson, kbarton, llvm-commits

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

llvm-svn: 327156
2018-03-09 18:03:22 +00:00
Rui Ueyama 7c18abf99a Set DF_TEXTREL to executables that need text relocations.
Summary:
If an executable needs text relocations, it should be marked as such so
that the loader can prepare for text relocations. We currently create a
dummy segment with DT_TEXTREL for that purpose.

Generic ABI as of 2000 [1] mentioned that "Its [DT_TEXTREL's] use
has been superseded by the DF_TEXTREL flag". However, it's actually not
superseded even after 18 years. OpenBSD and musl recognize only DT_TEXTREL.
So we still need to set both.

[1] http://www.sco.com/developers/gabi/2000-07-17/ch5.dynamic.html

Reviewers: rafael

Subscribers: emaste, llvm-commits, arichardson

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

llvm-svn: 326503
2018-03-01 22:56:52 +00:00
Rui Ueyama ee17371897 Merge {COFF,ELF}/Strings.cpp to Common/Strings.cpp.
This should resolve the issue that lld build fails in some hosts
that uses case-insensitive file system.

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

llvm-svn: 326339
2018-02-28 17:38:19 +00:00
George Rimar 563e4f2f58 [ELF] - Introduce getInputSections() helper.
We sometimes need to iterate over input sections for a given
output section. It is not very convinent because we have to iterate
over section descriptions.
Patch introduces getInputSections helper, it simplifies things.

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

llvm-svn: 325763
2018-02-22 09:55:28 +00:00
Alexander Richardson 048e2508ad Rename DynamicReloc::getAddend() to computeAddend(). NFC
Summary:
Before the name of the function sounded like it was just a getter for the
private class member Addend. However, it actually calculates the final
value for the r_addend field in Elf_Rela that is used when writing the
.rela.dyn section. I also added a comment to the UseSymVA member to
explain how it interacts with computeAddend().

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

llvm-svn: 325485
2018-02-19 11:00:15 +00:00
Rafael Espindola b960325989 Simplify RelocationBaseSection::addReloc.
Now that we have R_ADDEND, UseSymVA was redundant. We only want to
write the symbol virtual address when using an expression other than
R_ADDEND.

llvm-svn: 325360
2018-02-16 16:53:04 +00:00
Alexander Richardson cfb6093379 Ensure that Elf_Rel addends are always written for dynamic relocations
Summary:
This follows up on r321889 where writing of Elf_Rel addends was partially
moved to RelocationBaseSection. This patch ensures that the addends are
always written to the output section when a input section uses RELA but the
output is REL.

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

llvm-svn: 325328
2018-02-16 10:01:17 +00:00
Rafael Espindola d49866edba Use RelType in a few more places. NFC.
llvm-svn: 325017
2018-02-13 16:06:11 +00:00
Rafael Espindola 35cf8bbe36 Add a simpler version of addReloc. NFC.
Extracted from a patch by Alexander Richardson!

llvm-svn: 325016
2018-02-13 16:03:52 +00:00
Rui Ueyama ac114d27ae s/uncompress/decompress/g.
In lld, we use both "uncompress" and "decompress" which is confusing.
Since LLVM uses "decompress", we should use the same term.

llvm-svn: 324944
2018-02-12 21:56:14 +00:00
Rafael Espindola 7a7a81d9d1 Replace ApplyDynamicRelocs with WriteAddends.
The difference is that WriteAddends also takes IsRela into
consideration.

llvm-svn: 324271
2018-02-05 20:55:46 +00:00
Peter Smith 64f65b02d2 [ELF] Implement --[no-]apply-dynamic-relocs option.
When resolving dynamic RELA relocations the addend is taken from the
relocation and not the place being relocated. Accordingly lld does not
write the addend field to the place like it would for a REL relocation.
Unfortunately there is some system software, in particlar dynamic loaders
such as Bionic's linker64 that use the value of the place prior to
relocation to find the offset that they have been loaded at. Both gold
and bfd control this behavior with the --[no-]apply-dynamic-relocs option.
This change implements the option and defaults it to true for compatibility
with gold and bfd.

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

llvm-svn: 324221
2018-02-05 10:15:08 +00:00
Rafael Espindola 7ce2b4cd13 Simplify by sorting relocations before writing them.
llvm-svn: 323944
2018-02-01 03:17:12 +00:00
Rafael Espindola 6b2b45020c Use 4 as the alignment of .eh_frame_hdr.
It includes 32 bit values and this matches both gold and bfd.

llvm-svn: 323172
2018-01-23 05:23:23 +00:00
Rui Ueyama 2f8af79927 Avoid divisions.
Compiler doesn't know the fact that Config->WordSize * 8 is always a
power of two, so it had to use the div instruction to divide some
number with C.

llvm-svn: 323014
2018-01-20 00:14:16 +00:00
Rui Ueyama 517366c7e0 Make the bloom filter a bit larger.
I created https://reviews.llvm.org/D42202 to see how large the bloom
filter should be. With that patch, I tested various bloom filter sizes
with the following commands:

  $ cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_LLD=true \
    -DLLVM_ENABLE_PROJECTS='clang;lld' -DBUILD_SHARED_LIBS=ON \
    -DCMAKE_SHARED_LINKER_FLAGS=-Wl,-bloom-filter-bits=<some integer> \
    ../llvm-project/llvm
  $ rm -f $(find . -name \*.so.7.0.0svn)
  $ ninja lld
  $ LD_BIND_NOW=1 perf stat bin/ld.lld

Here is the result:

  -bloom-filter-bits=8   0.220351609 seconds
  -bloom-filter-bits=10  0.217146597 seconds
  -bloom-filter-bits=12  0.206870826 seconds
  -bloom-filter-bits=16  0.209456312 seconds
  -bloom-filter-bits=32  0.195092075 seconds

Currently we allocate 8 bits for a symbol, but according to the above
result, that number is not optimal. Even though the numbers follow the
diminishing return rule, the point where a marginal improvement becomes
too small is not -bloom-filter-bits=8 but 12. So this patch sets it to 12.

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

llvm-svn: 323010
2018-01-19 23:54:31 +00:00
Rui Ueyama e2dfdbf0aa Do not pass an argument that can be easily inferred from other argument.
llvm-svn: 322416
2018-01-12 22:29:29 +00:00
George Rimar 9fc2c64b35 [ELF] - Do not use HeaderSize for conditions in PltSection.
Previously we checked (HeaderSize == 0) to find out if
PltSection section is IPLT or PLT. Some targets does not set
HeaderSize though. For example PPC64 has no lazy binding implemented
and does not set PltHeaderSize constant.

Because of that using of both IPLT and PLT relocations worked
incorrectly there (testcase is provided).

Patch fixes the issue.

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

llvm-svn: 322362
2018-01-12 09:35:57 +00:00
Dimitry Andric 656714a311 Fix thread race between SectionPiece's OutputOff and Live members
Summary:
As reported in bug 35788, rL316280 reintroduces a race between two
members of SectionPiece, which share the same 64 bit memory location.

To fix the race, check the hash before checking the Live member, as
suggested by Rafael.

Reviewers: ruiu, rafael

Reviewed By: ruiu

Subscribers: smeenai, emaste, llvm-commits

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

llvm-svn: 322264
2018-01-11 08:03:22 +00:00
Shoaib Meenai d79bbf4474 [ELF] Fix SysV hash tables with --no-rosegment
When setting up the chain, we copy over the bucket's previous symbol
index, assuming that this index will be 0 (STN_UNDEF) for an unused
bucket (marking the end of the chain). When linking with --no-rosegment,
however, unused buckets will in fact contain the padding value, and so
the hash table will end up containing invalid chains. Zero out the hash
table section explicitly to avoid this, similar to what's already done
for GNU hash sections.

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

llvm-svn: 322259
2018-01-11 06:57:01 +00:00
Rafael Espindola 73584cb587 Centralize Config->IsRela handling.
This merges the two places were we check Config->IsRela to decide how
to write a relocation addend.

llvm-svn: 321889
2018-01-05 20:08:38 +00:00
George Rimar edb61167e5 [ELF] - Add missing dynamic tags when producing output with IRelative relocations only.
This is "Bug 35751 - .dynamic relocation entries omitted if output
contains only IFUNC relocations"

We have InX::RelaPlt and InX::RelaIPlt synthetic sections for PLT relocations.
They are usually live in rela.plt section. Problem appears when InX::RelaPlt
section is empty. In that case we did not produce normal set of dynamic tags
required, because logic was written in the way assuming we always have
non-IRelative relocations in rela.plt.

Patch fixes the issue.

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

llvm-svn: 321600
2017-12-31 07:42:54 +00:00
George Rimar 3208588e7a [ELF] - Remove excessive checks. NFC.
This was raised in comments for D41592.
With current code we always assign parent
section for Rel[a] sections like
InX::RelaPlt or InX::RelaDyn, so checking
their parent for null is excessive.

llvm-svn: 321581
2017-12-30 08:40:45 +00:00
Rafael Espindola ce3b52c186 Pass an InputFile to the InputSection constructor.
This simplifies toRegularSection and reduces the noise in a followup
patch.

llvm-svn: 321240
2017-12-21 02:11:51 +00:00
Rafael Espindola 5c73c49c9f Detemplate createCommentSection.
It was only templated so it could create a dummy section header that
was immediately parsed back.

llvm-svn: 321235
2017-12-21 01:21:59 +00:00
Rafael Espindola a32ddc4639 Use a reference for the shared symbol file.
Every shared symbol has a file, so we can use a reference.

llvm-svn: 321187
2017-12-20 16:28:19 +00:00
Igor Kudrin 5966d15943 [ELF] Fix an assignment command at the end of an .ARM.exidx section.
The value of the symbol in the assignment should include the sentinel entry.

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

llvm-svn: 321154
2017-12-20 08:56:10 +00:00
Rafael Espindola 1037eef8e0 Use references instead of pointers. NFC.
These values are trivially never null. While at it, also use
InputSection instead of InputSectionBase when possible.

llvm-svn: 321126
2017-12-19 23:59:35 +00:00
Rui Ueyama 22e5551ed7 Do not add .dynamic entries that don't have to be added early in the ctor. NFC.
We add dynamic section entries both in the ctor of the class and
DynamicSection::finalizeContents(). Some entries need to be added early
in the ctor because they add strings to .dynstr. Other entries were
intended to be added in finalizeContents(). However, some entries are
added in the ctor even though they don't add strings. This patch
fix the issue.

llvm-svn: 320851
2017-12-15 19:39:59 +00:00