Skip to content

Commit b8b2734

Browse files
committed
[DirectX] Add only-section to llvm-objcopy for DXContainer
1 parent 33d5a3b commit b8b2734

File tree

4 files changed

+377
-8
lines changed

4 files changed

+377
-8
lines changed

llvm/lib/ObjCopy/ConfigManager.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,13 @@ ConfigManager::getDXContainerConfig() const {
116116
!Common.AllocSectionsPrefix.empty() ||
117117
Common.DiscardMode != DiscardType::None || !Common.AddSection.empty() ||
118118
!Common.DumpSection.empty() || !Common.KeepSection.empty() ||
119-
!Common.OnlySection.empty() || !Common.SectionsToRename.empty() ||
120-
!Common.SetSectionAlignment.empty() || !Common.SetSectionFlags.empty() ||
121-
!Common.SetSectionType.empty() || Common.ExtractDWO ||
122-
Common.OnlyKeepDebug || Common.StripAllGNU || Common.StripDWO ||
123-
Common.StripDebug || Common.StripNonAlloc || Common.StripSections ||
124-
Common.StripUnneeded || Common.DecompressDebugSections ||
125-
Common.GapFill != 0 || Common.PadTo != 0 ||
126-
Common.ChangeSectionLMAValAll != 0 ||
119+
!Common.SectionsToRename.empty() || !Common.SetSectionAlignment.empty() ||
120+
!Common.SetSectionFlags.empty() || !Common.SetSectionType.empty() ||
121+
Common.ExtractDWO || Common.OnlyKeepDebug || Common.StripAllGNU ||
122+
Common.StripDWO || Common.StripDebug || Common.StripNonAlloc ||
123+
Common.StripSections || Common.StripUnneeded ||
124+
Common.DecompressDebugSections || Common.GapFill != 0 ||
125+
Common.PadTo != 0 || Common.ChangeSectionLMAValAll != 0 ||
127126
!Common.ChangeSectionAddress.empty()) {
128127
return createStringError(
129128
llvm::errc::invalid_argument,

llvm/lib/ObjCopy/DXContainer/DXContainerObjcopy.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ static Error handleArgs(const CommonConfig &Config, Object &Obj) {
2828
return Config.ToRemove.matches(P.Name);
2929
};
3030

31+
if (!Config.OnlySection.empty())
32+
RemovePred = [&Config](const Part &P) {
33+
// Explicitly keep these sections regardless of previous removes and
34+
// remove everything else.
35+
return !Config.OnlySection.matches(P.Name);
36+
};
37+
3138
if (auto E = Obj.removeParts(RemovePred))
3239
return E;
3340

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## Tests that the copied DXContainer correctly retains only the specified
2+
## headers.
3+
4+
# RUN: yaml2obj %s -o %t
5+
# RUN: llvm-objcopy --only-section=FKE1 --only-section=FKE4 %t %t.out
6+
# RUN: obj2yaml %t.out | FileCheck %s
7+
8+
--- !dxcontainer
9+
Header:
10+
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
11+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
12+
Version:
13+
Major: 1
14+
Minor: 0
15+
## FileSize = 32 (header)
16+
## + 8 (FKE1 content) + 1688 (FKE4 content)
17+
## + 8 (2 part offsets) + 16 (2 part headers)
18+
## = 1752
19+
# CHECK: FileSize: 1752
20+
FileSize: 1996
21+
# CHECK-NEXT: PartCount: 2
22+
PartCount: 7
23+
# CHECK-NEXT: PartOffsets: [ 40, 56 ]
24+
PartOffsets: [ 60, 76, 92, 108, 236, 1932, 1960 ]
25+
Parts:
26+
# CHECK-NEXT: Parts
27+
# CHECK: FKE1
28+
# CHECK-NOT: FKE2
29+
# CHECK-NOT: FKE3
30+
# CHECK: FKE4
31+
# CHECK-NOT: FKE5
32+
# CHECK-NOT: DXIL
33+
- Name: FKE0
34+
Size: 8
35+
- Name: FKE1
36+
Size: 8
37+
- Name: FKE2
38+
Size: 8
39+
- Name: FKE3
40+
Size: 120
41+
- Name: FKE4
42+
Size: 1688
43+
- Name: FKE5
44+
Size: 20
45+
- Name: DXIL
46+
Size: 28
47+
Program:
48+
MajorVersion: 6
49+
MinorVersion: 5
50+
ShaderKind: 5
51+
Size: 8
52+
DXILMajorVersion: 1
53+
DXILMinorVersion: 5
54+
DXILSize: 4
55+
DXIL: [ 0x42, 0x43, 0xC0, 0xDE, ]
56+
...

0 commit comments

Comments
 (0)