aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/ArchiveWriter.cpp
AgeCommit message (Collapse)AuthorFilesLines
22 hours[Object][Archive] Recompute headers and symbol map when switching from COFF ↵Jacek Caban1-2/+18
to GNU64 (#160606) COFF format has no 64-bit version, so we use GNU64 instead. Since this changes the headers, we need to recalculate everything. Fixes #160112.
2025-06-26Triple: Forward declare Twine and remove include (#145685)Matt Arsenault1-2/+2
2024-09-28[Object] Avoid repeated map lookups (NFC) (#110201)Kazu Hirata1-2/+1
2024-07-18Object: Don't error out on malformed bitcode files.pcc1-13/+51
An error reading a bitcode file most likely indicates that the file was created by a compiler from the future. Normally we don't try to implement forwards compatibility for bitcode files, but when creating an archive we can implement best-effort forwards compatibility by treating the file as a blob and not creating symbol index entries for it. lld and mold ignore the archive symbol index, so provided that you use one of these linkers, LTO will work as long as lld or the gold plugin is newer than the compiler. We only ignore errors if the archive format is one that is supported by a linker that is known to ignore the index, otherwise there's no chance of this working so we may as well error out. We print a warning on read failure so that users of linkers that rely on the symbol index can diagnose the issue. This is the same behavior as GNU ar when the linker plugin returns an error when reading the input file. If the bitcode file is actually malformed, it will be diagnosed at link time. Reviewers: MaskRay, dwblaikie, jh7370 Reviewed By: MaskRay, dwblaikie, jh7370 Pull Request: https://github.com/llvm/llvm-project/pull/96848
2024-07-09[llvm][object] Expose `writeArchiveToStream` (#98254)Jeff Niu1-4/+5
This internal helper is a useful API to have, when one wants to write an archive directly to some other preallocated stream.
2024-03-20[llvm-ar][Object][COFF] Add support for EC symbols to llvm-ar. (#85230)Jacek Caban1-11/+54
Make writeArchive IsEC argument optional and use EC symbol map when indicated by input object files.
2024-03-15[Object][Archive][NFC] Create all symbolic files objects before calculating ↵Jacek Caban1-35/+23
offsets. (#85229) This is refactoring preparing to move UseECMap computation to the archive writer. We currently require writeArchive caller to pass that. This is not practical for llvm-ar, which currently interprets at most one passed object. For a reliable UseECMap, we need to interpret all symbolic objects: we may have, for example, a list of x86_64 files followed by aarch64 file, which indicates that we should use EC map for x86_64 objects. This commit interprets symbolic files in a separated pass, which will be a convenient place to implement UseECMap computation in the follow up. It also makes accessing the next member for AIX big archive offset computation a bit easier.
2024-03-13[llvm-ar] Use COFF archive format for COFF targets. (#82898)Jacek Caban1-13/+15
Detect COFF files by default and allow specifying it with --format argument. This is important for ARM64EC, which uses a separated symbol map for EC symbols. Since K_COFF is mostly compatible with K_GNU, this shouldn't really make a difference for other targets. This originally landed as #82642, but was reverted due to test failures in tests using no symbol table. Since COFF symbol can't express it, fallback to GNU format in that case.
2024-03-12[Arm64EC] Copy import descriptors to the EC Map (#84834)Daniel Paoliello1-0/+11
As noted in <https://github.com/llvm/llvm-project/pull/78537>, MSVC places import descriptors in both the EC and regular map - that PR moved the descriptors to ONLY the regular map, however this causes linking errors when linking as Arm64EC: ``` bcryptprimitives.lib(bcryptprimitives.dll) : error LNK2001: unresolved external symbol __IMPORT_DESCRIPTOR_bcryptprimitives (EC Symbol) ``` This change copies import descriptors from the regular map to the EC map, which fixes this linking error.
2024-03-08[llvm][Support] Add and use errnoAsErrorCode (#84423)Michael Spencer1-1/+1
LLVM is inconsistent about how it converts `errno` to `std::error_code`. This can cause problems because values outside of `std::errc` compare differently if one is system and one is generic on POSIX systems. This is even more of a problem on Windows where use of the system category is just wrong, as that is for Windows errors, which have a completely different mapping than POSIX/generic errors. This patch fixes one instance of this mistake in `JSONTransport.cpp`. This patch adds `errnoAsErrorCode()` which makes it so people do not need to think about this issue in the future. It also cleans up a lot of usage of `errno` in LLVM and Clang.
2024-02-27[llvm-ar][Archive] Use getDefaultTargetTriple instead of host triple for the ↵Jacek Caban1-1/+1
fallback archive format. (#82888)
2024-02-24Revert "[llvm-ar] Use COFF archive format for COFF targets." (#82889)Jacek Caban1-11/+10
Reverts llvm/llvm-project#82642 for lld/test/ELF/invalid/Output/data-encoding.test.tmp.a failures on Windows.
2024-02-24[llvm-ar] Use COFF archive format for COFF targets. (#82642)Jacek Caban1-10/+11
Detect COFF files by default and allow specifying it with --format argument. This is important for ARM64EC, which uses a separated symbol map for EC symbols. Since K_COFF is mostly compatible with K_GNU, this shouldn't really make a difference for other targets.
2024-01-11[llvm] Use SmallString::operator std::string() (NFC)Kazu Hirata1-1/+1
2023-10-12Use llvm::endianness::{big,little,native} (NFC)Kazu Hirata1-2/+3
Note that llvm::support::endianness has been renamed to llvm::endianness while becoming an enum class as opposed to an enum. This patch replaces support::{big,little,native} with llvm::endianness::{big,little,native}.
2023-10-12[llvm-lib] [Object] Use ECSYMBOLS section for ARM64EC importlib symbols. ↵Jacek Caban1-0/+5
(#68328)
2023-09-06Fixed a compile error on use of deleted function ↵zhijian1-1/+1
¡®{anonymous}::MemberData::MemberData(const {anonymous}::MemberData&) Summary: There is compile error on https://lab.llvm.org/buildbot/#/builders/264/builds/1147/steps/5/logs/stdio when commit in https://reviews.llvm.org/D144872
2023-09-06[AIX] Align the content of an xcoff object file which has auxiliary header ↵zhijian1-73/+163
in big archive. Summary: if the member file is XCOFF object file and has auxiliary header, the content of the member file need to be aligned at the MAX(maximum alignment of .text , maximum alignment of .data). The "maximum alignment of .text" and "maximum alignment of .data" are two field of auxiliary header of XCOFF object file. Reviewers: James Henderson, Stephen Peckham Differential Revision: https://reviews.llvm.org/D144872
2023-09-01[llvm] Fix duplicate word typos. NFCFangrui Song1-1/+1
Those fixes were taken from https://reviews.llvm.org/D137338
2023-08-22[AIX] supporting -X options for llvm-ranlib in AIX OSzhijian1-15/+21
Summary: llvm-ar is symlinked as llvm-ranlib and will act as ranlib when invoked in that mode. llvm-ar since [[ https://github.ibm.com/compiler/llvm-project/commit/4f2cfbe5314b064625b2c87bde6ce5c8d04004c5 | compiler/llvm-project@4f2cfbe ]] supports the -X options, but doesn't seem to accept them when running as llvm-ranlib. In AIX OS , according to https://www.ibm.com/docs/en/aix/7.2?topic=r-ranlib-command -X mode Specifies the type of object file ranlib should examine. The mode must be one of the following: 32 Processes only 32-bit object files 64 Processes only 64-bit object files 32_64, any Processes both 32-bit and 64-bit object files The default is to process 32-bit object files (ignore 64-bit objects). The mode can also be set with the OBJECT_MODE environment variable. For example, OBJECT_MODE=64 causes ranlib to process any 64-bit objects and ignore 32-bit objects. The -X flag overrides the OBJECT_MODE variable. Reviewers: James Henderson, MaskRay, Stephen Peckham Differential Revision: https://reviews.llvm.org/D142660
2023-05-18[AIX] support 64bit global symbol table for big archivezhijian1-39/+151
Summary: In big archive , there is 32bit global symbol table and 64 bit global symbol table. llvm-ar only support 32bit global symbol table this moment, we need to support the 64 bit global symbol table. https://www.ibm.com/docs/en/aix/7.2?topic=formats-ar-file-format-big Global Symbol Tables Immediately following the member table, the archive file contains two global symbol tables. The first global symbol table locates 32-bit file members that define global symbols; the second global symbol table does the same for 64-bit file members. If the archive has no 32-bit or 64-bit file members, the respective global symbol table is omitted. The strip command can be used to delete one or both global symbol tables from the archive. The fl_gstoff field in the fixed-length header contains the offset to the 32-bit global symbol table, and the fl_gst64off contains the offset to the 64-bit global symbol table. Reviewers: James Henderson,Stephen Peckham Differential Revision: https://reviews.llvm.org/D142479
2023-05-16[AIX] Fixed malformed big archive when total archive file size is large than ↵zhijian1-7/+8
4Gbytes Summary: 1. we use the unsigned type for NextOffset,PrevOffset ,GlobalSymbolOffset , MemberTableSize, it will caused a malform big archive when the archive file size is large than 4G. 2. also fix a NFC comment on https://reviews.llvm.org/D142479#inline-1443927 Reviewers: James Henderson Differential Revision: https://reviews.llvm.org/D150462
2023-05-11llvm/lib: Use <cerrno> explicitly since D146395 has hidden `errno`NAKAMURA Takumi1-0/+1
Differential Revision: https://reviews.llvm.org/D149513
2023-04-28[AIX][llvm-ar] Use the Correct Kind for Bitcode File InputsQiongsi Wu1-2/+4
On AIX, when the input files are LLVM bitcode files, `llvm-ar` should set the archive kind to `K_AIXBIG` as well, instead of leaving it to the default `K_GNU`. Reviewed By: daltenty Differential Revision: https://reviews.llvm.org/D149377
2023-04-21[llvm-lib] Add support for ARM64EC libraries.Jacek Caban1-10/+73
ARM64EC allows having both pure ARM64 objects and ARM64EC in the same archive. This allows using single static library for linking pure ARM64, pure ARM64EC or mixed modules (what MS calls ARM64X: a single module that may be used in both modes). To achieve that, such static libraries need two separated symbol maps. The usual map contains only pure ARM64 symbols, while a new /<ECSYMBOLS>/ section contains EC symbols. EC symbols map has very similar format to the usual map, except it doesn't contain object offsets and uses offsets from regular map instead. This is true even for pure ARM64EC static library: it will simply have 0 symbols in the symbol map. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D143541
2023-03-23[llvm-lib] Use COFF archive format in llvm-lib (other archive tools don't ↵Jacek Caban1-22/+113
use this format). We currently just use GNU format for llvm-lib. This mostly works, but ARM64EC needs an additional section that does not really fit GNU format. This patch implements writing in COFF format (as in, it's what archive reader considers as K_COFF). This mostly requires symbol emitting symbol map. Note that, just like in case of MSVC, symbols are de-duplicated in both usual symbol table and the new symbol map. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D143540
2023-03-23[Object][NFC] Don't insert string table into object members vector.Jacek Caban1-6/+20
Having string table in members vector does not fit later patches in this series. Symbol map needs to refer to objects' offsets, but string table should not be referenced. Also for ARM64EC, the new <ECSYMBOLS> table is inserted after string table. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D143538
2023-03-23[Object][NFC] Factor out computeHeadersSize.Jacek Caban1-24/+40
In preparation for COFF archives support. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D143537
2022-09-10[Object] Improve ArchiveWriter diagnosticsYi Kong1-2/+2
Print out the archive member that failed, to make debugging easier. Before: error: failed to build archive: Not an int attribute (Producer: 'LLVM15.0.1git' Reader: 'LLVM 14.0.5-rust-dev') After: error: failed to build archive: 'fake_bt_keystore.o': Not an int attribute (Producer: 'LLVM15.0.1git' Reader: 'LLVM 14.0.5-rust-dev') Differential Revision: https://reviews.llvm.org/D133607
2022-05-19[Object] Fix updating darwin archivesKeith Smiley1-0/+37
When creating an archive, llvm-ar looks at the host to determine the archive format to use, on Apple platforms this means it uses the K_DARWIN format. K_DARWIN is _virtually_ equivalent to K_BSD, expect for some very slight differences around padding, timestamps in deterministic mode, and 64 bit formats. When updating an archive using llvm-ar, or llvm-objcopy, Archive would try to determine the kind, but it was not possible to get K_DARWIN in the initialization of the archive, because they're virtually inciting usable from K_BSD, especially since the slight differences only apply in very specific cases. This leads to linker failures when the alignment workaround is not applied to an archive copied with llvm-objcopy. This change teaches Archive to infer the K_DARWIN type in the cases where it's possible and the first object in the archive is a macho object. This avoids using the host triple to determine this to not affect cross compiling. Ideally we would eliminate the separate K_DARWIN type entirely since it's not a truly separate archive type, but then we'd have to force the macho workarounds on the BSD format generally. This might be acceptable but then it would be unclear how to handle this case without forcing the K_DARWIN64 format on all BSD users: ``` if (LastOffset >= Sym64Threshold) { if (Kind == object::Archive::K_DARWIN) Kind = object::Archive::K_DARWIN64; else Kind = object::Archive::K_GNU64; } ``` The logic used to determine if the object is macho is derived from the logic llvm-ar uses. Previous context: - 111cd669e90e5b2132187d36f8b141b11a671a8b - 23a76be5adcaa768ba538f8a4514a7afccf61988 Differential Revision: https://reviews.llvm.org/D124895
2022-05-13[AIX] support write operation of big archive.zhijian1-33/+163
SUMMARY 1. Enable supporting the write operation of big archive. 2. the first commit come from https://reviews.llvm.org/D104367 3. refactor the first commit and implement writing symbol table. 4. fixed the bugs and add more test cases in the second commit. Reviewers: James Henderson Differential Revision: https://reviews.llvm.org/D123949
2022-02-10Cleanup LLVMObject headersserge-sans-paille1-1/+0
Most notably, llvm/Object/Binary.h no longer includes llvm/Support/MemoryBuffer.h llvm/Object/MachOUniversal*.h no longer include llvm/Object/Archive.h llvm/Object/TapiUniversal.h no longer includes llvm/Object/TapiFile.h llvm-project preprocessed size: before: 1068185081 after: 1068324320 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D119457
2022-01-18[AIX] Support of Big archive (read)zhijian1-0/+2
Summary: The patch is based on the EGuesnet's implement of the "Support of Big archive (read) the first commit of the patch is come from https://reviews.llvm.org/D100651. the rest of commits of the patch 1 Addressed the comments on the https://reviews.llvm.org/D100651 2 according to https://www.ibm.com/docs/en/aix/7.2?topic=formats-ar-file-format-big using the "fl_fstmoff" for the first object file number, using "char ar_nxtmem[20]" to get next object file , using the "char fl_lstmoff[20]" for the last of the object file will fix the following problems: 2.1 can not correct reading a archive files which has padding data between too object file 2.2 can not correct reading a archive files from which some object file has be deleted 3 introduce a new derived class BigArchive for big ar file. Reviewers: James Henderson Differential Revision: https://reviews.llvm.org/D111889
2022-01-18Revert "[AIX] Support of Big archive (read)"Florian Hahn1-2/+0
This appears to be causing the following build failures on green dragon during stage2 builds on macOS: /System/Volumes/Data/jenkins/workspace/apple-clang-stage2-configure-RA_osceola/clang.roots/BuildRecords/clang-9999.99_install/Objects/obj-llvm/./bin/clang++ -fno-stack-protector -fno-common -Wno-profile-instr-unprofiled -Wno-unknown-warning-option -Werror=unguarded-availability-new -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -fmodules -fmodules-cache-path=/System/Volumes/Data/jenkins/workspace/apple-clang-stage2-configure-RA_osceola/clang.roots/BuildRecords/clang-9999.99_install/Objects/obj-llvm/tools/clang/stage2-bins/module.cache -fcxx-modules -Xclang -fmodules-local-submodule-visibility -gmodules -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -O2 -gline-tables-only -DNDEBUG -arch x86_64 -arch arm64 -arch arm64e -isysroot /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk -mmacosx-version-min=10.10 -Wl,-search_paths_first -Wl,-headerpad_max_install_names -Wl,-dead_strip tools/llvm-cov/CMakeFiles/llvm-cov.dir/llvm-cov.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/gcov.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/CodeCoverage.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/CoverageExporterJson.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/CoverageExporterLcov.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/CoverageFilters.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/CoverageReport.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/CoverageSummaryInfo.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/SourceCoverageView.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/SourceCoverageViewHTML.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/SourceCoverageViewText.cpp.o tools/llvm-cov/CMakeFiles/llvm-cov.dir/TestingSupport.cpp.o -o bin/llvm-cov -Wl,-rpath,@loader_path/../lib lib/libLLVMCore.a lib/libLLVMSupport.a lib/libLLVMObject.a lib/libLLVMCoverage.a lib/libLLVMProfileData.a lib/libLLVMDebugInfoDWARF.a lib/libLLVMObject.a lib/libLLVMBitReader.a lib/libLLVMCore.a lib/libLLVMRemarks.a lib/libLLVMBitstreamReader.a lib/libLLVMMCParser.a lib/libLLVMTextAPI.a lib/libLLVMMC.a lib/libLLVMBinaryFormat.a lib/libLLVMDebugInfoCodeView.a lib/libLLVMSupport.a -lm /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/lib/libz.tbd /Volumes/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/lib/libcurses.tbd lib/libLLVMDemangle.a && cd /System/Volumes/Data/jenkins/workspace/apple-clang-stage2-configure-RA_osceola/clang.roots/BuildRecords/clang-9999.99_install/Objects/obj-llvm/tools/clang/stage2-bins/tools/llvm-cov && xcrun dsymutil -o=llvm-cov.dSYM /System/Volumes/Data/jenkins/workspace/apple-clang-stage2-configure-RA_osceola/clang.roots/BuildRecords/clang-9999.99_install/Objects/obj-llvm/tools/clang/stage2-bins/bin/llvm-cov Undefined symbols for architecture x86_64: "llvm::object::CommonArchiveMemberHeader<llvm::object::BigArMemHdrType>::getRawAccessMode() const", referenced from: vtable for llvm::object::BigArchiveMemberHeader in libLLVMObject.a(Archive.cpp.o) "llvm::object::CommonArchiveMemberHeader<llvm::object::BigArMemHdrType>::getRawUID() const", referenced from: vtable for llvm::object::BigArchiveMemberHeader in libLLVMObject.a(Archive.cpp.o) "llvm::object::CommonArchiveMemberHeader<llvm::object::BigArMemHdrType>::getRawGID() const", referenced from: vtable for llvm::object::BigArchiveMemberHeader in libLLVMObject.a(Archive.cpp.o) "llvm::object::CommonArchiveMemberHeader<llvm::object::UnixArMemHdrType>::getRawAccessMode() const", referenced from: vtable for llvm::object::ArchiveMemberHeader in libLLVMObject.a(Archive.cpp.o) "llvm::object::CommonArchiveMemberHeader<llvm::object::UnixArMemHdrType>::getRawLastModified() const", referenced from: vtable for llvm::object::ArchiveMemberHeader in libLLVMObject.a(Archive.cpp.o) "llvm::object::CommonArchiveMemberHeader<llvm::object::BigArMemHdrType>::getRawLastModified() const", referenced from: vtable for llvm::object::BigArchiveMemberHeader in libLLVMObject.a(Archive.cpp.o) "llvm::object::CommonArchiveMemberHeader<llvm::object::BigArMemHdrType>::getOffset() const", referenced from: vtable for llvm::object::BigArchiveMemberHeader in libLLVMObject.a(Archive.cpp.o) "llvm::object::CommonArchiveMemberHeader<llvm::object::UnixArMemHdrType>::getRawUID() const", referenced from: vtable for llvm::object::ArchiveMemberHeader in libLLVMObject.a(Archive.cpp.o) "llvm::object::CommonArchiveMemberHeader<llvm::object::UnixArMemHdrType>::getRawGID() const", referenced from: vtable for llvm::object::ArchiveMemberHeader in libLLVMObject.a(Archive.cpp.o) "llvm::object::CommonArchiveMemberHeader<llvm::object::UnixArMemHdrType>::getOffset() const", referenced from: vtable for llvm::object::ArchiveMemberHeader in libLLVMObject.a(Archive.cpp.o) ld: symbol(s) not found for architecture x86_64 https://smooshbase.apple.com/ci/job/apple-clang-stage2-configure-RA_osceola/30276/console
2022-01-17[AIX] Support of Big archive (read)zhijian1-0/+2
Summary: The patch is based on the EGuesnet's implement of the "Support of Big archive (read) the first commit of the patch is come from https://reviews.llvm.org/D100651. the rest of commits of the patch 1 Addressed the comments on the https://reviews.llvm.org/D100651 2 according to https://www.ibm.com/docs/en/aix/7.2?topic=formats-ar-file-format-big using the "fl_fstmoff" for the first object file number, using "char ar_nxtmem[20]" to get next object file , using the "char fl_lstmoff[20]" for the last of the object file will fix the following problems: 2.1 can not correct reading a archive files which has padding data between too object file 2.2 can not correct reading a archive files from which some object file has be deleted 3 introduce a new derived class BigArchive for big ar file. Reviewers: James Henderson Differential Revision: https://reviews.llvm.org/D111889
2022-01-17Revert "[AIX] Support of Big archive (read)"zhijian1-2/+0
This reverts commit 3130134d6e4823b5ee7619288a4b7e1e60831a82.
2022-01-17[AIX] Support of Big archive (read)zhijian1-0/+2
Summary: The patch is based on the EGuesnet's implement of the "Support of Big archive (read) the first commit of the patch is come from https://reviews.llvm.org/D100651. the rest of commits of the patch 1 Addressed the comments on the https://reviews.llvm.org/D100651 2 according to https://www.ibm.com/docs/en/aix/7.2?topic=formats-ar-file-format-big using the "fl_fstmoff" for the first object file number, using "char ar_nxtmem[20]" to get next object file , using the "char fl_lstmoff[20]" for the last of the object file will fix the following problems: 2.1 can not correct reading a archive files which has padding data between too object file 2.2 can not correct reading a archive files from which some object file has be deleted 3 introduce a new derived class BigArchive for big ar file. Reviewers: James Henderson Differential Revision: https://reviews.llvm.org/D111889
2021-12-09[llvm] Add null-termination capability to SmallVectorMemoryBufferJan Svoboda1-1/+1
Most of `MemoryBuffer` interfaces expose a `RequiresNullTerminator` parameter that's being used to: * determine how to open a file (`mmap` vs `open`), * assert newly initialized buffer indeed has an implicit null terminator. This patch adds the paramater to the `SmallVectorMemoryBuffer` constructors, meaning: * null terminator can now be added to `SmallVector`s that didn't have one before, * `SmallVectors` that had a null terminator before keep it even after the move. In line with existing code, the new parameter is defaulted to `true`. This patch makes sure all calls to the `SmallVectorMemoryBuffer` constructor set it to `false` to preserve the current semantics. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D115331
2020-10-26[llvm-ar][Object] Fix detection of need for 64-bit archive symbol tablesAndrew Ng1-23/+47
The code to detect the requirement for 64-bit offsets in the archive symbol table was not correctly accounting for the archive file signature and the size of all the contents of the symbol table itself, e.g. the symbol table's header and string table. Also was not considering the variation in symbol table formats. This could result in the creation of large archives with a corrupt symbol table. Change the testing environment variable SYM64_THRESHOLD to be an absolute value rather than a power of 2 in order to enable precise testing of this detection code. Differential Revision: https://reviews.llvm.org/D89891
2020-10-01[Archive] Don't throw away errors for malformed archive membersJames Henderson1-19/+23
When adding an archive member with a problem, e.g. a new bitcode with an old archiver, containing an unsupported attribute, or an ELF file with a malformed symbol table, the archiver would throw away the error and simply add the member to the archive without any symbol entries. This meant that the resultant archive could be silently unusable when not using --whole-archive, and result in unexpected undefined symbols. This change fixes this issue by addressing two FIXMEs and only throwing away not-an-object errors. However, this meant that some LLD tests which didn't need symbol tables and were using invalid members deliberately to test the linker's malformed input handling no longer worked, so this patch also stops the archiver from looking for symbols in an object if it doesn't require a symbol table, and updates the tests accordingly. Differential Revision: https://reviews.llvm.org/D88288 Reviewed by: grimar, rupprecht, MaskRay
2020-08-13[llvm-libtool-darwin] Refactor ArchiveWriterSameer Arora1-10/+39
Refactoring function `writeArchive` in ArchiveWriter. Added a new function `writeArchiveBuffer` that returns the archive in a memory buffer instead of writing it out to the disk. This refactor is necessary so as to allow `llvm-libtool-darwin` to write universal files containing archives. Reviewed by jhenderson, MaskRay, smeenai Differential Revision: https://reviews.llvm.org/D84858
2020-04-18[Object] Change uint32_t getSymbolFlags() to Expected<uint32_t> ↵vgxbj1-4/+7
getSymbolFlags(). This change enables getSymbolFlags() to return errors which benefit error reporting in clients. Differential Revision: https://reviews.llvm.org/D77860
2020-03-11Drop a StringMap.h include, NFCReid Kleckner1-0/+1
$ diff -u <(sort thedeps-before.txt) <(sort thedeps-after.txt) \ | grep '^[-+] ' | sort | uniq -c | sort -nr 231 - llvm/include/llvm/ADT/StringMap.h 171 - llvm/include/llvm/Support/AllocatorBase.h 142 - llvm/include/llvm/Support/PointerLikeTypeTraits.h
2020-02-10Revert "Remove redundant "std::move"s in return statements"Bill Wendling1-4/+4
The build failed with error: call to deleted constructor of 'llvm::Error' errors. This reverts commit 1c2241a7936bf85aa68aef94bd40c3ba77d8ddf2.
2020-02-10Remove redundant "std::move"s in return statementsBill Wendling1-4/+4
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-1/+1
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2019-09-27[Alignment][NFC] Remove unneeded llvm:: scoping on Align typesGuillaume Chatelet1-5/+5
llvm-svn: 373081
2019-09-12[Alignment] Move OffsetToAlignment to Alignment.hGuillaume Chatelet1-6/+8
Summary: This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet, JDevlieghere, alexshap, rupprecht, jhenderson Subscribers: sdardis, nemanjai, hiraditya, kbarton, jakehehrlich, jrtc27, MaskRay, atanasyan, jsji, seiya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D67499 llvm-svn: 371742
2019-07-23[llvm-ar] Fix support for archives with members larger than 4GBOwen Reynolds1-6/+15
llvm-ar outputs a strange error message when handling archives with members larger than 4GB due to not checking file size when passing the value as an unsigned 32 bit integer. This overflow issue caused malformed archives to be created.: https://bugs.llvm.org/show_bug.cgi?id=38058 This change allows for members above 4GB and will error in a case that is over the formats size limit, a 10 digit decimal integer. Differential Revision: https://reviews.llvm.org/D65093 llvm-svn: 366813
2019-07-10[Support] Move llvm::MemoryBuffer to sys::fs::file_tReid Kleckner1-6/+7
Summary: On Windows, Posix integer file descriptors are a compatibility layer over native file handles provided by the C runtime. There is a hard limit on the maximum number of file descriptors that a process can open, and the limit is 8192. LLD typically doesn't run into this limit because it opens input files, maps them into memory, and then immediately closes the file descriptor. This prevents it from running out of FDs. For various reasons, I'd like to open handles to every input file and keep them open during linking. That requires migrating MemoryBuffer over to taking open native file handles instead of integer FDs. Reviewers: aganea, Bigcheese Reviewed By: aganea Subscribers: smeenai, silvas, mehdi_amini, hiraditya, steven_wu, dexonsmith, dang, llvm-commits, zturner Tags: #llvm Differential Revision: https://reviews.llvm.org/D63453 llvm-svn: 365588