Commit Graph

1795 Commits

Author SHA1 Message Date
Simon Atanasyan 55c2699d29 Follow-up to r221913. Fix some -Wcast-qual warning reasons.
llvm-svn: 221974
2014-11-14 07:15:43 +00:00
Shankar Easwaran c37f8af577 [ELF] Dynamic section was not aligned properly.
The dynamic section was not aligned properly. The alignment of the section is
determined by the word size of the architecture.

llvm-svn: 221972
2014-11-14 04:57:21 +00:00
Shankar Easwaran 0769c0ed0d [ELF] Fix the fileoffset according to the ELF spec.
With --no-align-segments, there is a bug that the fileoffset may not be
congruent to virtual address modulo page alignment.

This patch fixes the problem.

llvm-svn: 221890
2014-11-13 14:30:21 +00:00
Simon Atanasyan c77f5fa4f4 [ELF] Add CodeModel attribute to the DefinedAtom class
MIPS ELF symbols might contain some additional MIPS-specific flags
in the st_other field besides visibility ones. These flags indicate
code properties like microMIPS / MIPS16 encoding, position independent
code etc. We need to transfer the flags from input objects to the
output linked file to write them into the symbol table, adjust symbols
addresses etc.

I add new attribute CodeModel to the DefinedAtom class to hold target
specific flag and to get over YAML/Native format conversion barrier.
Other architectures/targets can extend CodeModel enumeration by their
own flags.

MIPS specific part of this patch adds support for STO_MIPS_MICROMIPS
flag. This flag marks microMIPS symbols. Such symbol should:
a) Has STO_MIPS_MICROMIPS in the corresponding .symtab record.
b) Has adjusted (odd) address in the corresponding .symtab
   and .dynsym records.

llvm-svn: 221864
2014-11-13 07:03:41 +00:00
Shankar Easwaran 74ce86cb83 [ELF] Fix segment alignment.
The segment alignment for PT_LOAD segments is set to page size by default, but
if any of the sections require an alignment more than the page size, the segment
alignment property is set to the maximum alignment of the sections that are part
of the segment.

llvm-svn: 221862
2014-11-13 04:33:06 +00:00
Shankar Easwaran 2e20049260 [ELF] Fix conditions for max-page-size.
Fix comments from Rui, also adds a test.

llvm-svn: 221860
2014-11-13 04:03:46 +00:00
Shankar Easwaran b43804b6f4 [ELF] Fix max-page-size option.
The user can use the max-page-size option and set the maximum page size. Dont
check for maximum allowed values for page size, as its what the kernel is
configured with.

Fix the test as well.

llvm-svn: 221858
2014-11-13 03:25:38 +00:00
Rui Ueyama 904cf593c1 [PECOFF] Fix delay-import address table contents.
Each entry in the delay-import address table had a wrong alignment
requirement if 32 bit. As a result it got wrong delay-import table.

Because llvm-readobj doesn't print out that field, we don't have a
test for that. I'll submit a test that would catch this bug after
improving llvm-readobj.

llvm-svn: 221853
2014-11-13 02:58:36 +00:00
Nick Kledzik 8870ad2439 [mach-o] Sort GOT entries by name to make links reproducible
The GOT slots were being laid out in a random order by the GOTPass which
caused randomness in the output file.

Note: With this change lld now bootstraps on darwin.  That is:
1) link lld using system linker to make lld.1
2) link lld using lld.1 to make lld.2
3) link lld using lld.2 to make lld.3
Now lld.2 and lld.3 are identical.

llvm-svn: 221831
2014-11-12 23:34:23 +00:00
Nick Kledzik 16cfa60cbd [mach-o] Support linker synthesized mach_header symbols.
On darwin in final linked images, the __TEXT segment covers that start of the
file.  That means in memory a process can see the mach_header (and load commands)
for every loaded image in a process.  There are APIs that take and return the
mach_header addresses as a way to specify a particular loaded image.

For completeness, any code can get the address of the mach_header of the image
it is in by using &__dso_handle.  In addition there are mach-o type specific
symbols like __mh_execute_header.

The linker needs to supply a definition for any of these symbols if used.  But
the address the symbol it resolves to is not in any section.  Instead it is the
address of the start of the __TEXT segment.

I needed to make a small change to SimpleFileNode to not override
resetNextIndex() because the Driver creates a SimpleFileNode to hold the
internal/implicit files that the context/writer can create. For some reason
SimpleFileNode overrode resetNextIndex() to do nothing instead of reseting
the index (which mach-o needs if the internal file is an archive).

llvm-svn: 221822
2014-11-12 22:21:56 +00:00
Nick Kledzik f373c77f50 [mach-o] Fix lazy binding offsets
The way lazy binding works in mach-o is that the linker generates a helper
function and has the stub (PLT) initially jump to it.  The helper function
pushes an extra parameter then jumps into dyld.  The extra parameter is an
offset into the lazy binding info where dyld will find the information about
which symbol to bind and way lazy binding pointer to update.

llvm-svn: 221654
2014-11-11 01:31:18 +00:00
Shankar Easwaran 0becd57044 [ELF] Change order of section match.
Addressed comments from Sean silva.

llvm-svn: 221650
2014-11-11 00:40:38 +00:00
Shankar Easwaran 48b9fc7981 Revert "Add support library."
This reverts commit r221583.

llvm-svn: 221649
2014-11-11 00:40:36 +00:00
Shankar Easwaran 1987862287 [Gnu][Driver] Use StringRef conversion functions
llvm-svn: 221648
2014-11-11 00:40:32 +00:00
Simon Atanasyan 7b2e2b7d01 [Mips] Replace the redundant condition by assert call
No functional changes.

llvm-svn: 221603
2014-11-10 15:50:22 +00:00
Simon Atanasyan 1255354141 [Mips] Do not read addends for relocations which do not use them
No functional changes.

llvm-svn: 221602
2014-11-10 15:50:01 +00:00
Shankar Easwaran 7757f1ace6 [Gnu] Support --image-base option
The value for --image-base is used as the base address of the program.

llvm-svn: 221589
2014-11-10 14:55:21 +00:00
Shankar Easwaran 7a82510348 [ELF] Fix DT_INIT_ARRAY{SZ} and DT_FINI_ARRAY{SZ}
The dynamic table was creating the entry DT_FINI_ARRAY{SZ} even when there was
no .fini_array section. The entries should be creating in the dynamic section
only if there are sections .init_array/.fini_array in the output.

Fixes the tests that checked for errroneous outputs.

llvm-svn: 221588
2014-11-10 14:55:11 +00:00
Shankar Easwaran 0abfc278f0 [ELF] Fix values of linker created dynamic variables.
The value of _DYNAMIC should be pointing at the start of the .dynamic segment.
This was pointing to the end of the dynamic segment. Similarly the value of
_GLOBAL_OFFSET_TABLE_ was not proper too.

llvm-svn: 221587
2014-11-10 14:55:07 +00:00
Shankar Easwaran 38d187021f [ELF] .dynamic should have SHT_DYNAMIC flag
llvm-svn: 221586
2014-11-10 14:54:53 +00:00
Shankar Easwaran 78aa81d6ed [Gnu] Add options that are ignored
Add options that are ignored and exists just for compatibility reasons.

llvm-svn: 221585
2014-11-10 14:54:49 +00:00
Shankar Easwaran ba154afa06 [ELF] Support -z max-page-size option
The GNU linker allows the user to change the page size by using the option -z
max-page-size.

llvm-svn: 221584
2014-11-10 14:54:43 +00:00
Shankar Easwaran c937b4923e Add support library.
The parsing routines in the linker script to parse strings encoded in various
formats(hexadecimal, octal, decimal, etc), is needed by the GNU driver too. This
library provides helper functions for all flavors and flavors to add helper
functions which other flavors may make use of.

llvm-svn: 221583
2014-11-10 14:54:34 +00:00
Shankar Easwaran 8f6dd44056 [ELF] Remove unused variable
llvm-svn: 221572
2014-11-08 04:03:24 +00:00
Shankar Easwaran 22c76a5d79 [ELF] Support --no-align-segments.
lld generates an ELF by adhering to the ELF spec by aligning vma/fileoffset to a
page boundary, but this becomes an issue when dealing with large pages. This
adds support so that lld generated executables adheres to the ELF spec with the
rule vma % p_align = offset % p_align.

This is supported by the flag --no-align-segments.

This could be the default in few targets like X86_64 to save space on disk.

llvm-svn: 221571
2014-11-08 03:44:49 +00:00
Nick Kledzik 466f80f1fc [mach-o] remove stray debug output
llvm-svn: 221553
2014-11-07 22:00:26 +00:00
Nick Kledzik f04ab0a244 [mach-o] Fix MachOFileNode to own archives same as ELFFileNode
My previous fix to have FileArchive own the member MemoryBuffers was not a
complete solution for darwin because nothing owned the FileArchive object.
Fixed MachOFileNode to be like ELFFileNode and have the graph node own the
archive object.

llvm-svn: 221552
2014-11-07 22:00:23 +00:00
Nick Kledzik 82d24bc932 [mach-o] Add support for -order_file option
The darwin linker lets you rearrange functions and data for better locality
(less paging).  You do this with the -order_file option which supplies a text
file containing one symbol per line.

Implementing this required a small change to LayoutPass to add a custom sorter
hook.

llvm-svn: 221545
2014-11-07 21:01:21 +00:00
Nick Kledzik 7bcfe288a8 Fix FileArchive member MemoryBuffer early destruction
When FileArchive loads a member, it instantiates a temporary MemoryBuffer
which points to the member range of the archive file.  The problem is that the
object file parsers call getBufferIndentifer() on that temporary MemoryBuffer
and store that StringRef as the _path data member for that lld::File.  When
FileArchive::instantiateMember() goes out of scope the MemoryBuffer is deleted
and the File::._path becomes a dangling reference.

The fix adds a vector<> to FileArchive to own the instantiated MemoryBuffers.
In addition it fixes member's path to be the standard format
(e.g. "/path/libfoo.a(foo.o)") instead of just the leaf name.

llvm-svn: 221544
2014-11-07 20:52:38 +00:00
Simon Atanasyan e77029cc5b [Mips] Do not hard-code the paired relocation type
Request `getPairRelocation()` function to get paired relocation type.
That allows us to look up another pairs like R_MICROMIPS_HI16/LO16
in the future.

llvm-svn: 221539
2014-11-07 19:32:08 +00:00
Shankar Easwaran 35cab83409 [ELF] Remove is64bits() and isLittlEndian().
ELFLinkingContext had these two functions, which is really not needed since
the Writer uses a llvm::object template composed of Endianness, Alignment,
Is32bit/64bit. We could just use that and not duplicate functionality.

No Change In Functionality.

llvm-svn: 221523
2014-11-07 14:08:43 +00:00
Rui Ueyama 2d220ab9b4 [PECOFF] Improve subsystem inference
If /subsystem option is not given, the linker needs to infer the
subsystem based on the entry point symbol. If it fails to infer
that, the linker should error out on it.

LLD was almost correct, but it would fail to infer the subsystem
if the entry point is specified with /entry. This is because the
subsystem inference was coupled with the entry point function
searching (if no entry point name is specified, the linker needs
to find the right entry name).

This patch makes the subsystem inference an independent pass to
fix the issue. Now, as long as an entry point function is defined,
LLD can infer the subsystem no matter how it resolved the entry
point.

I don't think scanning all the defined symbols is fast, although
it shouldn't be that slow. The file class there does not provide
any easy way to find an atom by name, so this is what we can do
at this moment. I'd like to revisit this later to make it more
efficient.

llvm-svn: 221499
2014-11-06 23:50:48 +00:00
Nick Kledzik babee83257 remove unneeded { }
llvm-svn: 221478
2014-11-06 19:33:59 +00:00
Nick Kledzik 24f504001d [mach-o] Add support for -force_load option
The darwin linker has two ways to force all members of an archive to be loaded.
The -all_load option applies to all static libraries.  The -force_load takes
a path to a library and just that library's members are force loaded.

llvm-svn: 221477
2014-11-06 19:33:57 +00:00
Simon Atanasyan c88db09cc5 [Mips] Take into account that PIC code is inherently CPIC
Follow-up to r221439.

llvm-svn: 221442
2014-11-06 07:07:29 +00:00
Simon Atanasyan e4f47f08a3 [Mips] Follow-up to r221439. Include header to fix build on Windows.
llvm-svn: 221440
2014-11-06 06:28:40 +00:00
Simon Atanasyan b915d07a8e [Mips] Check ELF flags to prevent linking of incompatible files
1. The path checks ELF header flags to prevent linking of incompatible files.
   For example we do not allow to link files with different ABI, -mnan
   flags, some combination of target CPU etc.
2. The patch merge ELF header flags from input object files to put their
   combination to the generated file. For example, if some input files
   have EF_MIPS_NOREORDER flag we need to put this flag to the output
   file header.

I use the `parseFile()` (not `canParse()`) method because in case of
recognition of incorrect input flags combination we should show detailed
error message and stop the linking process and should not try to use
another `Reader`.

llvm-svn: 221439
2014-11-06 05:53:10 +00:00
Shankar Easwaran 4446829883 [ELF] Remove llvm::Twine usage
llvm-svn: 221433
2014-11-06 03:03:58 +00:00
Nick Kledzik 8f75da0db3 [mach-o] Add support for -S option
The darwin linker does not process dwarf debug info.  Instead it produces a
"debug map" in the output file which points back to the original .o files for
anything that wants debug info (e.g. debugger).

The -S option means "don't add a debug map".  lld for mach-o currently does
not generate the debug map, so there is nothing to do when this option is used.
But we need to process the option to get existing projects building.

llvm-svn: 221432
2014-11-06 03:03:42 +00:00
Shankar Easwaran 7fea87cb59 [ELF] Remove includes that are not used
llvm-svn: 221430
2014-11-06 02:35:42 +00:00
Shankar Easwaran 2dfef4bfd6 [ELF] Use llvm::Twine
llvm-svn: 221428
2014-11-06 02:03:40 +00:00
Shankar Easwaran e27c59d9e5 [ELF] Implement isLittleEndian for all architectures
llvm-svn: 221427
2014-11-06 02:03:38 +00:00
Shankar Easwaran 0c501df3de [ELF] Use std::find_if instead
llvm-svn: 221426
2014-11-06 02:03:35 +00:00
Nick Kledzik 37d1aa715a [mach-o] remove extra leading underscore on __bss and __got
llvm-svn: 221425
2014-11-06 01:14:12 +00:00
Rui Ueyama 58942cc8ec [PECOFF] Add a comment for SECREL relocation.
llvm-svn: 221423
2014-11-06 01:14:02 +00:00
Nick Kledzik 5c4693d8d2 [mach-o] Add support for interposing tuples section
Darwin uses two-level-namespace lookup for symbols which means the static
linker records where each symbol must be found at runtime.  Thus defining a
symbol in a dylib loaded earlier will not effect where symbols needed by
later dylibs will be found.  Instead overriding is done through a section
of type S_INTERPOSING which contains tuples of <interposer, interposee>.

llvm-svn: 221421
2014-11-06 01:09:13 +00:00
Rui Ueyama 30804c4220 [PECOFF] Fix SECREL relocations.
SECREL relocation's value is the offset to the beginning of the section.
Because of the off-by-one error, if a SECREL relocation target is at the
beginning of a section, it got wrong value.

Added a test that would have caught this.

llvm-svn: 221420
2014-11-06 01:03:23 +00:00
Nick Kledzik 80118548d2 Fix shadowed variable warning
llvm-svn: 221414
2014-11-05 23:40:04 +00:00
David Majnemer 31fb9edc00 MachO: Remove an unused variable from processSection
The local variable `cfi` became dead in r220730 when it's use was
obviated; it was replaced with a call to read32.

No functionality change intended.

llvm-svn: 221412
2014-11-05 23:22:41 +00:00
Simon Atanasyan 7b1a5af229 [ELF] Use getVisibility() function to access st_other field
The st_other field can contains not only visibility flag so we should
retrieve a visibility flag using a bit-mask.

llvm-svn: 221397
2014-11-05 21:09:53 +00:00