aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object/COFFImportFile.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-12-26[llvm-dlltool] Handle MIPS R4000 architecture (#114621)Hervé Poussineau1-0/+2
2024-11-15[llvm-lib][llvm-dlltool] Fix handling of invalid ARM64EC function names ↵Jacek Caban1-1/+8
(#116250) This is a follow-up to #115567. Emit an error for invalid function names, similar to MSVC's `lib.exe` behavior. Returning an error from `writeImportLibrary` exposed bugs in error handling by its callers, which have been addressed in this patch.
2024-08-16[TableGen] Refactor Intrinsic handling in TableGen (#103980)Rahul Joshi1-1/+1
CodeGenIntrinsic changes: - Use `const` Record pointers, and `StringRef` when possible. - Default initialize several fields with their definition instead of in the constructor. - Simplify various string checks in the constructor using StringRef starts_with()/ends_with() functions. - Eliminate first argument to `setDefaultProperties` and use `TheDef` class member instead. IntrinsicEmitter changes: - Emit `namespace llvm::Intrinsic` instead of nested namespaces. - End generated comments with a . - Use range based for loops, and early continue within loops. - Emit `static constexpr` instead of `static const` for arrays. - Change `compareFnAttributes` to use std::tie() to compare intrinsic attributes and return a default value when all attributes are equal. STLExtras: - Add std::replace wrapper which takes a range.
2024-07-22[llvm-dlltool] Use EXPORTAS name type for renamed imports on ARM64EC. (#99346)Jacek Caban1-1/+4
Renamed entries are more tricky on ARM64EC than on other targets due to additional symbols (we need `__imp_aux_*` in addition to `__imp_*` and both mangled and unmangled symbol thunks). While we could extend weak aliases to add them, it seems cleaner to just always use EXPORTAS name type on ARM64EC targets. Unlike other targets, linkers supporting ARM64EC need to support EXPORTAS, so there is no compatibility problem with that.
2024-07-16[llvm-dlltool] Fix renamed imports without a separate regular import entry ↵Martin Storsjö1-11/+31
(#98229) Normally, when doing renamed imports, we do this by providing a weak alias, towards another regular import, for the symbol we want to actually import. In a def file, this looks like this: regularfunc renamedfunc == regularfunc However, if we want to link against a function in a DLL, where we (intentionally) don't provide a regular import for that symbol with the name in its DLL, doing the renamed import with a weak alias doesn't work, as there's no symbol that the weak alias can point towards. We can't make up such an import either, as we may intentionally not want to provide a regular import for that name. This situation can either be resolved by using the "long" import library format (as e.g. produced by GNU dlltool), or by using the new short import library name type "export as". This patch implements it by using the "export as" name type. When producing a renamed import, defer emitting it until all regular imports have been produced. If the renamed import refers to a symbol that does exist as a regular import entry, produce a weak alias, just as before. (This implementation also avoids needing to know whether the symbol that the alias points towards actually is prefixed or not, too.) If the renamed import points at a symbol that isn't otherwise available (or is available as a renamed symbol itself), generate an "export as" import entry. This name type is new, and is normally used in ARM64EC import libraries, but can also be used for other architectures.
2024-07-16[llvm-dlltool] Handle import renaming using other name types, when possible ↵Martin Storsjö1-21/+45
(#98228) This avoids needing to use weak aliases for these cases. (Weak aliases only work if there's another, regular import entry that provide the desired symbol from the DLL.)
2024-07-16[llvm-dlltool] Remove the i386 underscore prefix from ↵Martin Storsjö1-4/+10
COFFImportFile::ImportName. NFC. (#98226) On i386, regular C level symbols are given an underscore prefix in the symbols on the object file level. However, the exported names from DLLs usually don't have this leading underscore. When specified in a def file like "symbol == dllname", the "dllname" is the name of the exported symbol from the DLL, which will be linked against from an object file symbol named "_symbol" (on i386). The mechanism where one symbol is redirected to another one in an import library is implemented with weak aliases. In that case, we need to have the object file symbol level name for the target of the import, as we make one object file symbol point at another one. Therefore, we added an underscore to the ImportName field. (This mechanism, with weak aliases, only works as long as the target also is exported as is, in that form - this issue is dealt with in a later commit.) For clarity, for potentially handling the import renaming in other ways, store the ImportName field unprefixed, containing the actual name to import from the DLL. When creating the aliases, add the prefix as needed. This requires passing an extra AddUnderscores parameter to the writeImportLibrary function; this is a temporary measure, until alias creation is reworked in a later commit. This doesn't preserve the corner case of checking !isDecorated() before adding the prefix. This corner case isn't tested by any of our existing tests, and only would trigger for fastcall/vectorcall/MS C++ functions - while these kinds of renames primarily are used in mingw-w64-crt import libraries (which primarily handle cdecl and stdcall functions).
2024-07-11[llvm-dlltool] Respect the DATA flag when creating aliases (#98225)Martin Storsjö1-1/+3
2024-04-18[COFF] Rename the COFFShortExport::AliasTarget field. NFC. (#89039)Martin Storsjö1-3/+3
It turns out that the previous name is vaguely misleading. When operating on a def file like "symbolname == dllname", that is supposed to make an import library entry, that when the symbol "symbolname" links against this, it imports the DLL symbol "dllname" from the referenced DLL. This doesn't need to involve any alias, and it doesn't need to imply that "dllname" is available on its own as a separate symbol in the import library at all. GNU dlltool implements import libraries in the form of "long import library", where each member is a regular object file with section chunks that compose the relevant .idata section pieces. There, this kind of import renaming does not involve any form of aliases, but the right .idata section just gets a different string than the symbol name.
2024-03-31[Object][COFF][NFC] Don't use inline function for ↵Jacek Caban1-0/+21
COFFImportFile::printSymbolName. (#87195) Fixes BUILD_SHARED_LIBS builds after #87191 made helpers non-inline.
2024-03-27[llvm-dlltool][llvm-lib][COFF] Don't override NONAME exports with demangled ↵Jacek Caban1-2/+2
ARM64EC symbols. (#86722)
2024-03-21[llvm-lib] Use ARM64EC machine type for import libraries when ↵Jacek Caban1-2/+5
-machine:arm64x is used. (#85972) This is compatible with MSVC, `-machine:arm64x` is essentially an alias to `-machine:arm64ec`. To make a type library that exposes both native and EC symbols, an additional `-defArm64Native` argument is needed in both cases.
2024-03-12[Arm64EC] Copy import descriptors to the EC Map (#84834)Daniel Paoliello1-6/+4
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-02-15[llvm-dlltool] Add ARM64EC target support. (#81624)Jacek Caban1-1/+1
Add new target and a new -n option allowing to specify native module definition file, similar to how -defArm64Native works in llvm-lib. This also changes archive format to use K_COFF like non-mingw targets. It's required on ARM64EC, but it should be fine for other targets too.
2024-02-13[Object][COFF][NFC] Make writeImportLibrary NativeExports argument optional. ↵Jacek Caban1-2/+2
(#81600) It's not interesting for majority of downstream users.
2024-02-13[llvm-lib] Add support for -defArm64Native argument. (#81426)Jacek Caban1-52/+60
This can be used to create import libraries that contain both ARM64EC and native exports. The implementation follows observed MSVC lib.exe behaviour. It's ignored on targets other than ARM64EC.
2024-02-10[llvm-lib][Object] Add support for EC importlib symbols. (#81059)Jacek Caban1-0/+15
ARM64EC import libraries expose two additional symbols: mangled thunk symbol (like `#func`) and auxiliary import symbol (like`__imp_aux_func`). The main functional change with this patch is that those symbols are properly added to static library ECSYMBOLS.
2024-02-10[llvm-lib][llvm-dlltool][Object] Add support for EXPORTAS name types. (#78772)Jacek Caban1-21/+45
EXPORTAS is a new name type in import libraries. It's used by default on ARM64EC, but it's allowed on other platforms as well.
2024-02-06[llvm-readobj][Object][COFF] Print COFF import library symbol export name. ↵Jacek Caban1-0/+26
(#78769) getExportName implementation is based on lld-link. In its current form, it's mostly about convenience, but it will be more useful for EXPORTAS support, for which export name is not possible to deduce from other printed properties.
2024-01-19[llvm-lib][Object][COFF] Use ARM64 machine type for import library ↵Jacek Caban1-26/+35
descriptor objects. (#78537)
2024-01-17[llvm-readobj][Object][COFF] Include COFF import file machine type in format ↵Jacek Caban1-0/+19
string. (#78366)
2023-12-11[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)Kazu Hirata1-3/+3
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-10-12[llvm-lib] [Object] Use ECSYMBOLS section for ARM64EC importlib symbols. ↵Jacek Caban1-1/+2
(#68328)
2023-09-27[NFC] Use const references to avoid copying objects in for-loopsGregory Alfonso1-1/+1
Differential Revision: https://reviews.llvm.org/D139487
2023-09-15Object: account for short output names (#66532)Saleem Abdulrasool1-1/+1
The import library thunk name suffix uses the stem of the file. We currently would attempt to trim the suffix by dropping the trailing 4 characters (under the assumption that the output name was `.lib`). This now uses the `llvm::sys::path` API for computing the stem. This avoids an assertion failure when the name is less the 4 characters and assertions are enabled.
2023-08-22[AIX] supporting -X options for llvm-ranlib in AIX OSzhijian1-1/+1
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-07-28[Object] Use COFF archive format for import libraries.Jacek Caban1-1/+1
This is similar to D143540 for import libraries. ARM64EC will need it for EC symbol table, but it should be fine for other targets as well and it improves MSVC compatibility. I left mingw case unchanged to be safe, although I think that it wouldn't hurt to change that as well. The visible effect in tests is a sorted symbol map. Revieved By: mstorsjo Differential Revision: https://reviews.llvm.org/D156473
2023-07-28[Object] [NFC] Use llvm::COFF::is64Bit in COFF import file implementation.Jacek Caban1-25/+10
Reviewed By: jhenderson, efriedma Differential Revision: https://reviews.llvm.org/D156454
2023-04-21[llvm-lib] [llvm-readobj] [llvm-cvtres] Add Support for ARM64X object files.Jacek Caban1-0/+2
Similar to D125411, but for ARM64X. ARM64X PE binaries are hybrids containing both ARM64EC and pure ARM64 variants in one file. They are usually linked by passing separate ARM64EC and ARM64 object files to linker. Linked binaries use ARM64 machine and contain additional CHPE metadata in their load config. CHPE metadata support is not part of this patch, I plan to send that later. Using ARM64X as a machine type of object files themselves is somewhat ambiguous, but such files are allowed by MSVC. It treats them as ARM64 or ARM64EC object, depending on the context. Such objects can be produced with cvtres.exe -machine:arm64x. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D148517
2023-03-21[NFC] Change strcpy to std::copyIlyas Mustafazade1-1/+2
Differential Revision: https://reviews.llvm.org/D146382
2022-09-05[ARM64EC 1/?] Add parsing support to llvm-objdump/llvm-readobj.Eli Friedman1-0/+2
This is the first patch of a patchset to add initial support for ARM64EC. Basic documentation is available at https://docs.microsoft.com/en-us/windows/uwp/porting/arm64ec-abi . (Discourse post: https://discourse.llvm.org/t/initial-patches-for-arm64ec-windows-11-now-posted/62449 .) The file format for ARM64EC is basically identical to normal ARM64. There are a few extra sections, but the existing code for reading ARM64 object files just works. Differential Revision: https://reviews.llvm.org/D125411
2022-02-10Cleanup LLVMObject headersserge-sans-paille1-0/+4
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
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-05-22[llvm-dlltool] Respect NONAME keywordMartin Storsjo1-1/+4
This adds proper handling of the NONAME-keyword, which makes llvm-dlltool generate an import using the ordinal instead of the name. Patch by by Jannik Vogel, test added by Stefan Schmidt. Differential Revision: https://reviews.llvm.org/D62175 llvm-svn: 361367
2019-03-26[llvm-dlltool] Set a proper machine type for weak symbol object filesMartin Storsjo1-1/+1
This makes GNU binutils not reject the libraries outright. GNU ld handles weak externals slightly differently though, so it can't use them for aliases in import libraries, but this makes GNU ld able to use the rest of the import libraries. LLD accepted object files with machine type 0 aka IMAGE_FILE_MACHINE_UNKNOWN. Differential Revision: https://reviews.llvm.org/D59742 llvm-svn: 356982
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
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
2018-07-20[COFF] Use symbolic constants instead of hardcoded numbers. NFCI.Martin Storsjo1-1/+6
Patch by Martell Malone. llvm-svn: 337614
2018-05-09[COFF] Improve correctness of def parsing for GNU featuresMartin Storsjo1-8/+7
The operator == used for exporting a function with a different name in the DLL compared to the name in the import library (which is useful for adding linker level aliases for function in the import library) is a feature distinct and different from the operator = used for exporting a function with a different name (both in import library and DLL) than in the implementation producing the DLL. When creating an import library using dlltool, from a def file that contains forwards (Func = OtherDll.Func), this shouldn't affect the produced import library, which should still behave just as if it was a normal exported function. This clears a lot of confusion and subtle misunderstandings, and avoids a parameter that was used to avoid creating weak aliases when invoked from lld. (This parameter was added previously due to the existing conflation of the two features.) Differential Revision: https://reviews.llvm.org/D46245 llvm-svn: 331859
2018-01-20[COFF] Keep the underscore on exported decorated stdcall functions in MSVC modeMartin Storsjo1-3/+12
This (together with the corresponding LLD commit, that contains the testcase updates) fixes PR35733. Differential Revision: https://reviews.llvm.org/D41631 llvm-svn: 323035
2017-12-15Fixed the gcc 'enumeral and non-enumeral type in conditional expression ↵Galina Kistanova1-3/+3
[-Werror=extra]' warning introduced by r320750 llvm-svn: 320868
2017-12-13Remove redundant includes from lib/Object.Michael Zolotukhin1-2/+0
llvm-svn: 320625
2017-09-21Convert the archive writer to use Error.Rafael Espindola1-6/+5
This found one place in lld that was not checking the error. llvm-svn: 313937
2017-08-30Simplify writeArchive return type.Rui Ueyama1-5/+3
writeArchive returned a pair, but the first element of the pair is always its first argument on failure, so it doesn't make sense to return it from the function. This patch change the return type so that it does't return it. Differential Revision: https://reviews.llvm.org/D37313 llvm-svn: 312177
2017-08-16[COFF] Make the weak aliases optionalMartin Storsjo1-2/+2
When creating an import library from lld, the cases with Name != ExtName shouldn't end up as a weak alias, but as a real export of the new name, which is what actually is exported from the DLL. This restores the behaviour of renamed exports to what it was in 4.0. The other half of this commit, including test, goes into lld. Differential Revision: https://reviews.llvm.org/D36633 llvm-svn: 310991
2017-08-16[COFF] Add SymbolName as a distinct field in COFFImportFileMartin Storsjo1-1/+1
The previous Name and ExtName aren't enough to convey all the nuances between weak aliases and stdcall decorated function names. A test for this will be added in LLD. Differential Revision: https://reviews.llvm.org/D36544 llvm-svn: 310988
2017-07-31[llvm-dlltool] Write correct weak externalsMartin Storsjo1-8/+5
Previously, the created object files for the import library were broken. Write the symbol table before the string table. Simplify the code by using a separate variable Prefix instead of duplicating a few lines. Also update the coff-weak-exports to actually check that the generated weak symbols can be found as intended. Differential Revision: https://reviews.llvm.org/D36065 llvm-svn: 309555
2017-07-25[COFF] ARM64 support for COFFImportFileMartin Storsjo1-0/+3
A test will be committed separately in the lld repo. Differential Revision: https://reviews.llvm.org/D35766 llvm-svn: 308951
2017-07-18Object: rename parameter from DLLName to ImportNameSaleem Abdulrasool1-16/+16
When I originally wrote this code, I neglected the fact that the import library may be created for executables. This name is not the name of the DLL, but rather the name for the imported module. It will be embedded into the IAT/ILT reference. Rename it to make it more obvious. NFC. llvm-svn: 308384
2017-07-18llvm: add llvm-dlltool support to the archiverMartell Malone1-13/+101
A PE COFF spec compliant import library generator. Intended to be used with mingw-w64. Supports: PE COFF spec (section 8, Import Library Format) PE COFF spec (Aux Format 3: Weak Externals) Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D29892 This reapplies rL308329, which was reverted in rL308374 llvm-svn: 308379
2017-07-18Revert r308329: llvm: add llvm-dlltool support to the archiverRui Ueyama1-101/+13
This reverts commit r308329 because it broke buildbots. llvm-svn: 308374