Skip to content

Commit 659ed24

Browse files
authored
[DirectX] Add only-section to llvm-objcopy for DXContainer (#156372)
This pr implements the `only-section` option for a `DXContainer` object in `llvm-objcopy`. It extends the base `removeParts` of the minimal object representation of a `DXContainerObject`. This a pre-requisite step to implement #150286 as a way to strip all other information away.
1 parent 79d2961 commit 659ed24

File tree

4 files changed

+167
-8
lines changed

4 files changed

+167
-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: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 --implicit-check-not=Name:
7+
8+
## FileSize = 32 (header)
9+
## + 8 (FKE1 content) + 1688 (FKE4 content)
10+
## + 8 (2 part offsets) + 16 (2 part headers)
11+
## = 1752
12+
# CHECK: FileSize: 1752
13+
# CHECK-NEXT: PartCount: 2
14+
# CHECK-NEXT: PartOffsets: [ 40, 56 ]
15+
# CHECK-NEXT: Parts
16+
# CHECK-NEXT: Name: FKE1
17+
# CHECK-NEXT: Size: 8
18+
# CHECK-NEXT: Name: FKE4
19+
# CHECK-NEXT: Size: 1688
20+
21+
--- !dxcontainer
22+
Header:
23+
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
24+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
25+
Version:
26+
Major: 1
27+
Minor: 0
28+
FileSize: 1996
29+
PartCount: 7
30+
PartOffsets: [ 60, 76, 92, 108, 236, 1932, 1960 ]
31+
Parts:
32+
- Name: FKE0
33+
Size: 8
34+
- Name: FKE1
35+
Size: 8
36+
- Name: FKE2
37+
Size: 8
38+
- Name: FKE3
39+
Size: 120
40+
- Name: FKE4
41+
Size: 1688
42+
- Name: FKE5
43+
Size: 20
44+
- Name: DXIL
45+
Size: 28
46+
Program:
47+
MajorVersion: 6
48+
MinorVersion: 5
49+
ShaderKind: 5
50+
Size: 8
51+
DXILMajorVersion: 1
52+
DXILMinorVersion: 5
53+
DXILSize: 4
54+
DXIL: [ 0x42, 0x43, 0xC0, 0xDE, ]
55+
...
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
## Tests that the copied DXContainer correctly retains only the RTS0 part even
2+
## when it was defined to be removed.
3+
4+
# RUN: yaml2obj %s -o %t
5+
# RUN: llvm-objcopy --remove-section=RTS0 --only-section=RTS0 %t %t.out
6+
# RUN: obj2yaml %t.out | FileCheck %s --implicit-check-not=Name:
7+
8+
## The DXContainer described below was generated with:
9+
10+
## `clang-dxc -T cs_6_7 test.hlsl /Fo temp.dxo`
11+
## `obj2yaml temp.dxo`
12+
13+
## ``` test.hlsl
14+
## [RootSignature("")]
15+
## [numthreads(1,1,1)]
16+
## void main() {}
17+
## ```
18+
19+
## FileSize = 32 + 24 (RTS0 content) + 4 (1 part offset) + 8 (1 part header)
20+
## = 68
21+
# CHECK: FileSize: 68
22+
# CHECK-NEXT: PartCount: 1
23+
# CHECK-NEXT: PartOffsets: [ 36 ]
24+
# CHECK-NEXT: Parts
25+
# CHECK-NEXT: Name: RTS0
26+
27+
--- !dxcontainer
28+
Header:
29+
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
30+
0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
31+
Version:
32+
Major: 1
33+
Minor: 0
34+
FileSize: 1984
35+
PartCount: 7
36+
PartOffsets: [ 60, 1792, 1808, 1836, 1852, 1868, 1900 ]
37+
Parts:
38+
- Name: DXIL
39+
Size: 1724
40+
Program:
41+
MajorVersion: 6
42+
MinorVersion: 7
43+
ShaderKind: 5
44+
Size: 28
45+
DXILMajorVersion: 1
46+
DXILMinorVersion: 7
47+
DXILSize: 4
48+
DXIL: [ 0x42, 0x43, 0xC0, 0xDE, ]
49+
- Name: SFI0
50+
Size: 8
51+
- Name: HASH
52+
Size: 20
53+
Hash:
54+
IncludesSource: false
55+
Digest: [ 0x9F, 0xD1, 0xD9, 0xE2, 0x49, 0xFB, 0x3A, 0x6C,
56+
0x8C, 0x14, 0x8A, 0x96, 0x1C, 0x7D, 0x85, 0xA9 ]
57+
- Name: ISG1
58+
Size: 8
59+
Signature:
60+
Parameters: []
61+
- Name: OSG1
62+
Size: 8
63+
Signature:
64+
Parameters: []
65+
- Name: RTS0
66+
Size: 24
67+
RootSignature:
68+
Version: 2
69+
NumRootParameters: 0
70+
RootParametersOffset: 24
71+
NumStaticSamplers: 0
72+
StaticSamplersOffset: 24
73+
Parameters: []
74+
- Name: PSV0
75+
Size: 76
76+
PSVInfo:
77+
Version: 3
78+
ShaderStage: 5
79+
MinimumWaveLaneCount: 0
80+
MaximumWaveLaneCount: 4294967295
81+
UsesViewID: 0
82+
SigInputVectors: 0
83+
SigOutputVectors: [ 0, 0, 0, 0 ]
84+
NumThreadsX: 1
85+
NumThreadsY: 1
86+
NumThreadsZ: 1
87+
EntryName: main
88+
ResourceStride: 24
89+
Resources: []
90+
SigInputElements: []
91+
SigOutputElements: []
92+
SigPatchOrPrimElements: []
93+
InputOutputMap:
94+
- [ ]
95+
- [ ]
96+
- [ ]
97+
- [ ]
98+
...

0 commit comments

Comments
 (0)