summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter
Commit message (Collapse)AuthorAgeFilesLines
* [lld] Fix trivial typos in commentsKazuaki Ishizaki2020-01-067-12/+12
| | | | | | Reviewed By: ruiu, MaskRay Differential Revision: https://reviews.llvm.org/D72196
* [lld] Fix -Wrange-loop-analysis warningsFangrui Song2020-01-011-1/+1
| | | | | | | | | | One instance looks like a false positive: lld/ELF/Relocations.cpp:1622:14: note: use reference type 'const std::pair<ThunkSection *, uint32_t> &' (aka 'cons t pair<lld::elf::ThunkSection *, unsigned int> &') to prevent copying for (const std::pair<ThunkSection *, uint32_t> ts : isd->thunkSections) It is not changed in this commit.
* [MachO] Fix detecting malformed DWARF.Igor Kudrin2019-12-171-2/+2
| | | | | | | This fixes an invalid constant used to detect the reserved range when reading the compilation unit header. See also: D64622 and D65039. Differential Revision: https://reviews.llvm.org/D71546
* Revert "Fix shared lib build."Rui Ueyama2019-11-191-1/+0
| | | | | | | This reverts commit 17e37ba57a696198c9744eeba4f8f293f155587a because it introduced a circular dependency between Core and Common. Because d0371f473675ede1d79a615ec4fdf0cf5368944c fixed a build issue, we no longer need that dependency.
* Fix component buildRui Ueyama2019-11-194-5/+5
| | | | | b11386f9be9b2dc7276a758d64f66833da10bdea broke lld build if `-DBUILD_SHARED_LIBS=ON` is passed to CMake.
* Fix shared lib build.Michael Liao2019-11-181-0/+1
|
* Make it possible to redirect not only errs() but also outs()Rui Ueyama2019-11-184-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This change is for those who use lld as a library. Context: https://reviews.llvm.org/D70287 This patch adds a new parmeter to lld::*::link() so that we can pass an raw_ostream object representing stdout. Previously, lld::*::link() took only an stderr object. Justification for making stdoutOS and stderrOS mandatory: I wanted to make link() functions to take stdout and stderr in that order. However, if we change the function signature from bool link(ArrayRef<const char *> args, bool canExitEarly, raw_ostream &stderrOS = llvm::errs()); to bool link(ArrayRef<const char *> args, bool canExitEarly, raw_ostream &stdoutOS = llvm::outs(), raw_ostream &stderrOS = llvm::errs()); , then the meaning of existing code that passes stderrOS silently changes (stderrOS would be interpreted as stdoutOS). So, I chose to make existing code not to compile, so that developers can fix their code. Differential Revision: https://reviews.llvm.org/D70292
* Move endian constant from Host.h to SwapByteOrder.h, prune includeReid Kleckner2019-10-191-0/+1
| | | | | | | | | | | | | | Works on this dependency chain: ArrayRef.h -> Hashing.h -> --CUT-- Host.h -> StringMap.h / StringRef.h ArrayRef is very popular, but Host.h is rarely needed. Move the IsBigEndianHost constant to SwapByteOrder.h. Clients of that header are more likely to need it. llvm-svn: 375316
* [lld][mach-o] Avoid segfaulting when handling an empty section list.Matt Davis2019-09-261-6/+8
| | | | | | | | | | | | | | | | | Summary: The following patch avoids segfaulting if the section list is empty when writing a mach-o MH_OBJECT. I ran into this case from a more complicated example trying to dead_strip while using '-r' in lld. I'm not sure if having empty sections is a legal mach-o, but it does seem that other llvm-binutils tools can ingest such a boring object with out issue. Would it be better to emit an error, emit a warning, or do nothing? It seems that adding a warning diagnostic might be helpful to users, as I did not expect to have a section-less object when the linker was done. Reviewers: kledzik, ruiu Subscribers: llvm-commits, jrm Tags: #lld, #llvm Differential Revision: https://reviews.llvm.org/D67735 llvm-svn: 372995
* [mach-o] Extend LC_DATA_IN_CODE support to x86_64Rui Ueyama2019-08-281-8/+42
| | | | | | | | Patch by LemonBoy Differential Revision: https://reviews.llvm.org/D62185 llvm-svn: 370183
* [LLD] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-1410-16/+16
| | | | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368936
* [MachO] Update LLD to use 64-bit offsets with DataExtractor (3/5)Igor Kudrin2019-08-061-6/+6
| | | | | | Differential Revision: https://reviews.llvm.org/D65639 llvm-svn: 368032
* Rename F_{None,Text,Append} to OF_{None,Text,Append}. NFCFangrui Song2019-08-052-3/+3
| | | | | | F_{None,Text,Append} are kept for compatibility since r334221. llvm-svn: 367800
* Use llvm::stable_sortFangrui Song2019-04-231-5/+4
| | | | | | | | | Make some small adjustment while touching the code: make parameters const, use less_first(), etc. Differential Revision: https://reviews.llvm.org/D60989 llvm-svn: 358943
* lld: Fix initial Mach-O load commands size calculation omitting ↵Rui Ueyama2019-04-173-12/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | LC_FUNCTION_STARTS Patch by Nicholas Allegra. The Mach-O writer calculates the size of load commands multiple times. First, Util::assignAddressesToSections() (in MachONormalizedFileFromAtoms.cpp) calculates the size using headerAndLoadCommandsSize() (in MachONormalizedFileBinaryWriter.cpp), which creates a temporary MachOFileLayout for the NormalizedFile, only to retrieve its headerAndLoadCommandsSize. Later, writeBinary() (in MachONormalizedFileBinaryWriter.cpp) creates a new layout and uses the offsets from that layout to actually write out everything in the NormalizedFile. But the NormalizedFile changes between the first computation and the second. When Util::assignAddressesToSections is called, file.functionStarts is always empty because Util::addFunctionStarts has not yet been called. Yet MachOFileLayout decides whether to include a LC_FUNCTION_STARTS command based on whether file.functionStarts is nonempty. Therefore, the initial computation always omits it. Because padding for the __TEXT segment (to make its size a multiple of the page size) is added between the load commands and the first section, LLD still generates a valid binary as long as the amount of padding happens to be large enough to fit LC_FUNCTION_STARTS command, which it usually is. However, it's easy to reproduce the issue by adding a section of a precise size. Given foo.c: __attribute__((section("__TEXT,__foo"))) char foo[0xd78] = {0}; Run: clang -dynamiclib -o foo.dylib foo.c -fuse-ld=lld -install_name /usr/lib/foo.dylib otool -lvv foo.dylib This should produce: truncated or malformed object (offset field of section 1 in LC_SEGMENT_64 command 0 not past the headers of the file) This commit: - Changes MachOFileLayout to always assume LC_FUNCTION_STARTS is present for the initial computation, as long as generating LC_FUNCTION_STARTS is enabled. It would be slightly better to check whether there are actually any functions, since no LC_FUNCTION_STARTS will be generated if not, but it doesn't cause a problem if the initial computation is too high. - Adds a test. - Adds an assert in MachOFileLayout::writeSectionContent() that we are not writing section content into the load commands region (which would happen if the offset was calculated too low due to the initial load commands size calculation being too low). Adds an assert in MachOFileLayout::writeLoadCommands to validate a similar situation where two size-of-load-commands computations are expected to be equivalent. llvm-svn: 358545
* [ELF][MachO][wasm] Simplify range-style std::find{,_if} with STLExtras.h ↵Fangrui Song2019-03-293-13/+7
| | | | | | utilities. NFC llvm-svn: 357269
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-1932-128/+96
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* Fix clang -Wimplicit-fallthrough warnings across llvm, NFCReid Kleckner2018-11-012-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | This patch should not introduce any behavior changes. It consists of mostly one of two changes: 1. Replacing fall through comments with the LLVM_FALLTHROUGH macro 2. Inserting 'break' before falling through into a case block consisting of only 'break'. We were already using this warning with GCC, but its warning behaves slightly differently. In this patch, the following differences are relevant: 1. GCC recognizes comments that say "fall through" as annotations, clang doesn't 2. GCC doesn't warn on "case N: foo(); default: break;", clang does 3. GCC doesn't warn when the case contains a switch, but falls through the outer case. I will enable the warning separately in a follow-up patch so that it can be cleanly reverted if necessary. Reviewers: alexfh, rsmith, lattner, rtrieu, EricWF, bollu Differential Revision: https://reviews.llvm.org/D53950 llvm-svn: 345882
* MachO: Change getString16() back to inline functionTom Stellard2018-09-071-1/+1
| | | | | | This was accidentally changed in r341670. llvm-svn: 341672
* MachO: Fix out-of-bounds memory access in getString16Tom Stellard2018-09-071-6/+5
| | | | | | | | | | | | | | | | | | Summary: This fixes the following tests when gcc is compiled with gcc8: lld :: mach-o/do-not-emit-unwind-fde-arm64.yaml lld :: mach-o/eh-frame-relocs-arm64.yaml llvm.org/PR38096 Reviewers: lhames, kledzik, javed.absar Subscribers: kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D51547 llvm-svn: 341670
* Fix -DBUILD_SHARED_LIBS=1 buildSam Clegg2018-06-121-0/+1
| | | | | | This was broken in rL334466 llvm-svn: 334507
* [Darwin] Use errorHandler from liblldCommonBrian Gesiak2018-06-121-8/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Error handling in liblldCore and the Darwin toolchain prints to an output stream. A TODO in the project explained that a diagnostics interface resembling Clang's should be added. For now, the simple diagnostics interface defined in liblldCommon seems like an improvement. It prints colors when they're available, uses locks for thread-safety, and abstracts away the `"error: "` and newline literal strings that litter the Darwin toolchain code. To use the liblldCommon error handler, a link dependency is added to the liblldDriver library. Test Plan: 1. check-lld 2. Invoke `ld64.lld -r` in a terminal that supports color output. Confirm that "ld64.lld: error: -arch not specified and could not be inferred" is output, and that the "error:" is colored red! Reviewers: ruiu, smeenai Reviewed By: ruiu Subscribers: mgorny, llvm-commits Differential Revision: https://reviews.llvm.org/D47998 llvm-svn: 334466
* Remove \brief commands from doxygen comments.Fangrui Song2018-05-151-3/+3
| | | | | | | | | | | | Summary: This is similar to D46290 D46320. Reviewers: ruiu, grimar Subscribers: mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D46861 llvm-svn: 332372
* [lld] Update uses of DEBUG macro to LLVM_DEBUG.Nicola Zaghen2018-05-153-37/+41
| | | | | | | | | | | The DEBUG() macro is very generic so it might clash with other projects. The renaming was done as follows: - git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g' - git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 -style LLVM Differential Revision: https://reviews.llvm.org/D44977 llvm-svn: 332351
* Fix build broken by llvm r327486Pavel Labath2018-03-141-1/+1
| | | | | | llvm::DWARFFormParams moved to llvm::dwarf::FormParams. llvm-svn: 327489
* [ELF] Fix IsPreemptible comment and typo. NFCFangrui Song2018-02-231-2/+2
| | | | llvm-svn: 325963
* [YAML] Fix mustQuote return type changed in r320996Francis Visoiu Mistrih2017-12-182-6/+6
| | | | llvm-svn: 320997
* MachONormalizedFile.h: Remove unimplemented functionDavid Blaikie2017-11-221-9/+0
| | | | | | | dump had no definition, so op<< was never usable anyway - remove the definition of the latter and the declaration of the former. llvm-svn: 318880
* Make some headers modular by adding missing includes/forward decls.David Blaikie2017-11-211-0/+2
| | | | llvm-svn: 318718
* Update for llvm change.Rafael Espindola2017-11-081-1/+2
| | | | llvm-svn: 317657
* Update for llvm change.Rafael Espindola2017-11-081-3/+3
| | | | llvm-svn: 317650
* lld: Prune unused libdeps.NAKAMURA Takumi2017-10-121-1/+0
| | | | llvm-svn: 315537
* lld: Reorder libdeps.NAKAMURA Takumi2017-10-111-1/+1
| | | | | | Differential Revision: https://reviews.llvm.org/D38828 llvm-svn: 315529
* Move new lld's code to Common subdirectory.Rui Ueyama2017-10-0215-15/+15
| | | | | | | | | | New lld's files are spread under lib subdirectory, and it isn't easy to find which files are actually maintained. This patch moves maintained files to Common subdirectory. Differential Revision: https://reviews.llvm.org/D37645 llvm-svn: 314719
* [MACH-O] Fix the ASM code generated for __stub_helpers sectionRui Ueyama2017-08-246-0/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Patch by Patricio Villalobos. I discovered that lld for darwin is generating the wrong code for lazy bindings in the __stub_helper section (at least for osx 10.12). This is the way i can reproduce this problem, using this program: #include <stdio.h> int main(int argc, char **argv) { printf("C: printf!\n"); puts("C: puts!\n"); return 0; } Then I link it using i have tested it in 3.9, 4.0 and 4.1 versions: $ clang -c hello.c $ lld -flavor darwin hello.o -o h1 -lc When i execute the binary h1 the system gives me the following error: C: printf! dyld: lazy symbol binding failed: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment 4 which is too large (0..3) dyld: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB has segment 4 which is too large (0..3) Trace/BPT trap: 5 Investigating the code, it seems that the problem is that the asm code generated in the file StubPass.cpp, specifically in the line 323,when it adds, what it seems an arbitrary number (12) to the offset into the lazy bind opcodes section, but it should be calculated depending on the MachONormalizedFileBinaryWrite::lazyBindingInfo result. I confirmed this bug by patching the code manually in the binary and writing the right offset in the asm code (__stub_helper). This patch fixes the content of the atom that contains the assembly code when the offset is known. Differential Revision: https://reviews.llvm.org/D35387 llvm-svn: 311734
* Fix ObjCPass on big-endian hostTom Stellard2017-07-241-2/+6
| | | | | | | | | | | | | | | | Summary: This fixes test/mach-o/objc-image-info-pass-output.yaml on big-endian hosts. Reviewers: lhames, kledzik, ruiu Reviewed By: ruiu Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D35052 llvm-svn: 308935
* lld matching change for llvm change r308690 to add error handling toKevin Enderby2017-07-201-1/+4
| | | | | | the dyld compact export entries in libObject. llvm-svn: 308691
* [MachO] Add missing byte-swaps when reading dyld_infoTom Stellard2017-07-071-3/+3
| | | | | | | | | | | | | | | | | | | | Summary: This fixes the following tests on big-endian hosts: lld :: mach-o/dylib-install-names.yaml lld :: mach-o/force_load-dylib.yaml lld :: mach-o/lib-search-paths.yaml lld :: mach-o/upward-dylib-load-command.yaml Reviewers: lhames, kledzik, ruiu Reviewed By: ruiu Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D35022 llvm-svn: 307405
* Fix ODR violations due to abuse of LLVM_YAML_IS_(FLOW_)?SEQUENCE_VECTORRichard Smith2017-06-301-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | This is a short-term fix for PR33650 aimed to get the modules build bots green again. Remove all the places where we use the LLVM_YAML_IS_(FLOW_)?SEQUENCE_VECTOR macros to try to locally specialize a global template for a global type. That's not how C++ works. Instead, we now centrally define how to format vectors of fundamental types and of string (std::string and StringRef). We use flow formatting for the former cases, since that's the obvious right thing to do; in the latter case, it's less clear what the right choice is, but flow formatting is really bad for some cases (due to very long strings), so we pick block formatting. (Many of the cases that were using flow formatting for strings are improved by this change.) Other than the flow -> block formatting change for some vectors of strings, this should result in no functionality change. Differential Revision: https://reviews.llvm.org/D34907 Corresponding LLVM change is r306878. llvm-svn: 306880
* Tweak to match change in LLVM API, in r306315.Paul Robinson2017-06-261-2/+2
| | | | llvm-svn: 306316
* Added LLVM_FALLTHROUGH to address warning: this statement may fall through. NFC.Galina Kistanova2017-06-101-0/+1
| | | | llvm-svn: 305145
* Move Object format code to lib/BinaryFormat.Zachary Turner2017-06-0712-27/+32
| | | | | | | | | | | | This creates a new library called BinaryFormat that has all of the headers from llvm/Support containing structure and layout definitions for various types of binary formats like dwarf, coff, elf, etc as well as the code for identifying a file from its magic. Differential Revision: https://reviews.llvm.org/D33843 llvm-svn: 304864
* [Support] Move Parallel algorithms from LLD to LLVM.Zachary Turner2017-05-111-2/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D33024 llvm-svn: 302748
* [Core] Make parallel algorithms match C++ Parallelism TS.Zachary Turner2017-05-101-4/+4
| | | | | | Differential Revision: https://reviews.llvm.org/D33016 llvm-svn: 302613
* [MachO/X86_64] Simplify isDataInCodeTransition().Davide Italiano2017-04-151-8/+1
| | | | llvm-svn: 300385
* [MachO/AArch64] Merge multiple switch cases into one. NFCI.Davide Italiano2017-04-151-4/+0
| | | | llvm-svn: 300384
* [CMake] Fix pthread handling for out-of-tree buildsEric Fiselier2017-02-101-1/+1
| | | | | | | | | | | | | | | LLVM defines `PTHREAD_LIB` which is used by AddLLVM.cmake and various projects to correctly link the threading library when needed. Unfortunately `PTHREAD_LIB` is defined by LLVM's `config-ix.cmake` file which isn't installed and therefore can't be used when configuring out-of-tree builds. This causes such builds to fail since `pthread` isn't being correctly linked. This patch attempts to fix that problem by renaming and exporting `LLVM_PTHREAD_LIB` as part of`LLVMConfig.cmake`. I renamed `PTHREAD_LIB` because It seemed likely to cause collisions with downstream users of `LLVMConfig.cmake`. llvm-svn: 294690
* [lld][cmake] Fix LLVM_LINK_LLVM_DYLIB buildPavel Labath2017-01-093-7/+15
| | | | | | | | | | | | | | | | | | | | | | | Summary: Lld's build had a couple of issues which prevented a successfull LLVM_LINK_LLVM_DYLIB compilation. - add_llvm_library vs llvm_add_library: One adds a library to libLLVM.so, other one doesn't. Lld was using the wrong one, causing symbols to be mupltiply defined in things linking to libLLVM. - confusion when to use LINK_LIBS vs LINK_COMPONENTS in llvm_add_library - not using LLVM_LINK_COMPONENTS for add_lld_tool With these fixes lld compiles and it's test suite passes both in LLVM_LINK_LLVM_DYLIB mode and without it. Reviewers: ruiu, beanz Subscribers: llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D28397 llvm-svn: 291432
* Remove unnecessary llvm/Config/config.h includesMichal Gorny2016-12-141-1/+0
| | | | | | | | | | | | | | | | | | Remove the includes of <llvm/Config/config.h> private LLVM header. The relevant files seem not to use any definitions from that file, and it is not available when building against installed LLVM. The use in lib/ReaderWriter/MachO/MachOLinkingContext.cpp originates from rL218718, and the use in ELF/Strings.cpp from rL274804 (where it was moved from Symbols.cpp). In both cases, they were added as a part of demangling support, and they provided HAVE_CXXABI_H. Since we are now using the LLVM demangler library instead, the code was removed and the includes and no longer necessary. Differential Revision: https://reviews.llvm.org/D27757 llvm-svn: 289707
* Fix wrong formatting in lld introduced in r286561 (NFC)Mehdi Amini2016-11-115-5/+5
| | | | | | Pointed out by Davide. llvm-svn: 286649
OpenPOWER on IntegriCloud