-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm-ar] Use COFF archive format for COFF targets. #82642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+114
−15
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
Verify that llvm-ar uses COFF archive format by ensuring that archive map is sorted. | ||
|
||
RUN: rm -rf %t.dif && split-file %s %t.dir && cd %t.dir | ||
|
||
RUN: yaml2obj coff-symtab.yaml -o coff-symtab.obj | ||
RUN: llvm-ar crs out.a coff-symtab.obj | ||
RUN: llvm-nm --print-armap out.a | FileCheck %s | ||
|
||
RUN: llvm-as coff-symtab.ll -o coff-symtab.bc | ||
RUN: llvm-ar crs out2.a coff-symtab.bc | ||
RUN: llvm-nm --print-armap out2.a | FileCheck %s | ||
|
||
RUN: yaml2obj elf.yaml -o coff-symtab.o | ||
RUN: llvm-ar crs --format coff out3.a coff-symtab.o | ||
RUN: llvm-nm --print-armap out3.a | FileCheck %s | ||
|
||
CHECK: Archive map | ||
CHECK-NEXT: a in coff-symtab | ||
CHECK-NEXT: b in coff-symtab | ||
CHECK-NEXT: c in coff-symtab | ||
CHECK-EMPTY: | ||
|
||
#--- coff-symtab.yaml | ||
--- !COFF | ||
header: | ||
Machine: IMAGE_FILE_MACHINE_UNKNOWN | ||
Characteristics: [ ] | ||
sections: | ||
- Name: .text | ||
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] | ||
Alignment: 4 | ||
SectionData: '' | ||
symbols: | ||
- Name: b | ||
Value: 0 | ||
SectionNumber: 1 | ||
SimpleType: IMAGE_SYM_TYPE_NULL | ||
ComplexType: IMAGE_SYM_DTYPE_FUNCTION | ||
StorageClass: IMAGE_SYM_CLASS_EXTERNAL | ||
- Name: c | ||
Value: 0 | ||
SectionNumber: 1 | ||
SimpleType: IMAGE_SYM_TYPE_NULL | ||
ComplexType: IMAGE_SYM_DTYPE_FUNCTION | ||
StorageClass: IMAGE_SYM_CLASS_EXTERNAL | ||
- Name: a | ||
Value: 0 | ||
SectionNumber: 1 | ||
SimpleType: IMAGE_SYM_TYPE_NULL | ||
ComplexType: IMAGE_SYM_DTYPE_FUNCTION | ||
StorageClass: IMAGE_SYM_CLASS_EXTERNAL | ||
... | ||
|
||
|
||
#--- coff-symtab.ll | ||
target triple = "x86_64-unknown-windows-msvc" | ||
|
||
define void @b() { ret void } | ||
define void @c() { ret void } | ||
define void @a() { ret void } | ||
|
||
#--- elf.yaml | ||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data : ELFDATA2LSB | ||
Type: ET_REL | ||
Machine: EM_X86_64 | ||
Sections: | ||
- Name: .text | ||
Type: SHT_PROGBITS | ||
Flags: [ SHF_ALLOC, SHF_EXECINSTR ] | ||
AddressAlign: 0x0000000000000004 | ||
Content: '' | ||
Symbols: | ||
- Name: b | ||
Binding: STB_GLOBAL | ||
Section: .text | ||
- Name: c | ||
Binding: STB_GLOBAL | ||
Section: .text | ||
- Name: a | ||
Binding: STB_GLOBAL | ||
Section: .text | ||
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a little nervous about how this impacts the default archive format on a Windows host: our downstream uses a cross-compiler, typically hosted on Windows, but using GNU-style archives (and the objects therefore have a different triple too).
I'm going to suggest to our internal binutils team that they run some testing with this patch applied, to see if it makes any difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note the host matters only when
llvm-ar
can't infer the format from any other source. In practice, it means that it matters only when creating empty archives and archives who's first member is a non-symbolic files. In typical use case, when you pass object files, this PR shouldn't change anything unless you use COFF files.I could limit impact of this PR by not changing the effect of
getDefaultKindForHost
, but it feels right to be consistent. If we consider those cases to be a problem, then it's also problematic for existingisOSDarwin()
andisOSAIX()
checks (which have even more significant format differences). If user cares about the format and usesllvm-ar
on non-symbolic files, then an explicit--format
argument is the only reliable way I can see to handle all cross compilation variants.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jh7370, I checked and this will change our downstream ar's output in the cases @cjacek highlights above. However, due to @cjacek's points I cannot argue against it's submission.
The current behavior that default output format is defined by host does not seem good for the cross-compile use case in general. It may be preferable for the default to be based on the CMAKE option LLVM_DEFAULT_TARGET_TRIPLE or something similar to gnu binutils and the GNUTARGET environment variable. Both are likely out of the scope of this PR though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLVM_DEFAULT_TARGET_TRIPLE sounds like a good idea, I will create a separated PR for it, thanks.