-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[lld][COFF] Remove duplicate strtab entries #141197
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4204ca0
[lld][COFF] Remove duplicate strtab entries
HaohaiWen a4a6c91
Using prioritized StringTableBuilder
HaohaiWen 8e034a8
Merge remote-tracking branch 'origin/main' into strtab
HaohaiWen 47e5b2c
Add test
HaohaiWen 333a908
Fix ObjCopy
HaohaiWen 1f428ce
Merge remote-tracking branch 'origin/main' into strtab
bd00aba
Address comments
HaohaiWen ff8fce2
Update llvm/include/llvm/MC/StringTableBuilder.h
HaohaiWen ac31e68
split llvm-copy changes to another PR
HaohaiWen 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# RUN: llvm-mc -triple=x86_64-windows-msvc %s -filetype=obj -o %t.obj | ||
# RUN: lld-link -out:%t.exe -entry:main %t.obj -debug:dwarf | ||
# RUN: llvm-readobj --string-table %t.exe | FileCheck %s | ||
|
||
# CHECK: StringTable { | ||
# CHECK-NEXT: Length: 87 | ||
# CHECK-NEXT: [ 4] .debug_abbrev | ||
# CHECK-NEXT: [ 12] .debug_line | ||
# CHECK-NEXT: [ 1e] long_name_symbolz | ||
# CHECK-NEXT: [ 30] .debug_abbrez | ||
# CHECK-NEXT: [ 3e] __impl_long_name_symbolA | ||
# CHECK-NEXT: } | ||
|
||
|
||
.global main | ||
.text | ||
main: | ||
long_name_symbolz: | ||
long_name_symbolA: | ||
__impl_long_name_symbolA: | ||
name_symbolA: | ||
.debug_abbrez: | ||
ret | ||
|
||
.section .debug_abbrev,"dr" | ||
.byte 0 | ||
|
||
.section .debug_line,"dr" | ||
.byte 0 |
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 |
---|---|---|
|
@@ -38,6 +38,8 @@ class StringTableBuilder { | |
}; | ||
|
||
private: | ||
// Only non-zero priority will be recorded. | ||
DenseMap<CachedHashStringRef, uint8_t> StringPriorityMap; | ||
DenseMap<CachedHashStringRef, size_t> StringIndexMap; | ||
size_t Size = 0; | ||
Kind K; | ||
|
@@ -51,11 +53,16 @@ class StringTableBuilder { | |
LLVM_ABI StringTableBuilder(Kind K, Align Alignment = Align(1)); | ||
LLVM_ABI ~StringTableBuilder(); | ||
|
||
/// Add a string to the builder. Returns the position of S in the | ||
/// table. The position will be changed if finalize is used. | ||
/// Can only be used before the table is finalized. | ||
LLVM_ABI size_t add(CachedHashStringRef S); | ||
size_t add(StringRef S) { return add(CachedHashStringRef(S)); } | ||
/// Add a string to the builder. Returns the position of S in the table. The | ||
/// position will be changed if finalize is used. Can only be used before the | ||
/// table is finalized. Priority is only useful with reordering. Strings with | ||
/// the same priority will be put together. Strings with higher priority are | ||
/// placed closer to the begin of string table. When adding same string with | ||
/// different priority, the maximum priority win. | ||
LLVM_ABI size_t add(CachedHashStringRef S, uint8_t Priority = 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should mention what if a string is added with different priorities. (std::max below) |
||
size_t add(StringRef S, uint8_t Priority = 0) { | ||
return add(CachedHashStringRef(S), Priority); | ||
} | ||
|
||
/// Analyze the strings and build the final table. No more strings can | ||
/// be added after this point. | ||
|
@@ -78,6 +85,7 @@ class StringTableBuilder { | |
bool contains(StringRef S) const { return contains(CachedHashStringRef(S)); } | ||
bool contains(CachedHashStringRef S) const { return StringIndexMap.count(S); } | ||
|
||
bool empty() const { return StringIndexMap.empty(); } | ||
size_t getSize() const { return Size; } | ||
LLVM_ABI void clear(); | ||
|
||
|
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
Oops, something went wrong.
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.
Does it work if x86 is not configured?
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.
It does not: https://lab.llvm.org/buildbot/#/builders/190/builds/21872
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 have marked the test as requiring x86 in 757c80d.
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! I didn't aware of that.