Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
16975929
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
16975929
编写于
7月 07, 2015
作者:
T
Tomáš Matoušek
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3855 from tmat/PEWriterCleanup3
Remove unused PE sections
上级
da5b06b2
50228440
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
9 addition
and
115 deletion
+9
-115
src/Compilers/Core/Portable/PEWriter/PeWriter.cs
src/Compilers/Core/Portable/PEWriter/PeWriter.cs
+9
-115
未找到文件。
src/Compilers/Core/Portable/PEWriter/PeWriter.cs
浏览文件 @
16975929
...
...
@@ -43,19 +43,11 @@ internal sealed class PeWriter
private
NtHeader
_ntHeader
;
private
CoffHeader
_coffHeader
;
private
readonly
BlobWriter
_rdataWriter
=
new
BlobWriter
();
private
readonly
BlobWriter
_sdataWriter
=
new
BlobWriter
();
private
readonly
BlobWriter
_tlsDataWriter
=
new
BlobWriter
();
private
readonly
BlobWriter
_win32ResourceWriter
=
new
BlobWriter
(
1024
);
private
readonly
BlobWriter
_coverageDataWriter
=
new
BlobWriter
();
private
SectionHeader
_coverSection
;
private
SectionHeader
_relocSection
;
private
SectionHeader
_resourceSection
;
private
SectionHeader
_rdataSection
;
private
SectionHeader
_sdataSection
;
private
SectionHeader
_textSection
;
private
SectionHeader
_tlsSection
;
private
PeWriter
(
ModulePropertiesForSerialization
properties
,
...
...
@@ -198,10 +190,6 @@ private bool WritePeToStream(MetadataWriter mdWriter, Func<Stream> getPeStream,
nativePdbContentId
,
out
metadataPosition
);
WriteRdataSection
(
peStream
);
WriteSdataSection
(
peStream
);
WriteCoverSection
(
peStream
);
WriteTlsSection
(
peStream
);
WriteResourceSection
(
peStream
);
WriteRelocSection
(
peStream
);
...
...
@@ -320,10 +308,6 @@ private short GetSectionCount()
{
short
sectionCount
=
1
;
// .text
if
(
_properties
.
RequiresStartupStub
)
sectionCount
++;
//.reloc
if
(
_tlsDataWriter
.
Length
>
0
)
sectionCount
++;
//.tls
if
(
_rdataWriter
.
Length
>
0
)
sectionCount
++;
//.rdata
if
(
_sdataWriter
.
Length
>
0
)
sectionCount
++;
//.sdata
if
(
_coverageDataWriter
.
Length
>
0
)
sectionCount
++;
//.cover
if
(!
IteratorHelper
.
EnumerableIsEmpty
(
_nativeResourcesOpt
)
||
_nativeResourceSectionOpt
!=
null
)
sectionCount
++;
//.rsrc;
return
sectionCount
;
...
...
@@ -407,7 +391,7 @@ private void FillInNtHeader(MetadataSizes metadataSizes, int mappedFieldDataStre
ntHeader
.
MinorLinkerVersion
=
_properties
.
LinkerMinorVersion
;
ntHeader
.
AddressOfEntryPoint
=
_properties
.
RequiresStartupStub
?
mappedFieldDataStreamRva
-
(
_is32bit
?
6
:
10
)
:
0
;
// TODO: constants
ntHeader
.
BaseOfCode
=
textSectionRva
;
ntHeader
.
BaseOfData
=
_r
dataSection
.
RelativeVirtualAddress
;
ntHeader
.
BaseOfData
=
_r
esourceSection
.
RelativeVirtualAddress
;
// TODO: first section containing initialized data?
ntHeader
.
ImageBase
=
_properties
.
BaseAddress
;
ntHeader
.
FileAlignment
=
_properties
.
FileAlignment
;
ntHeader
.
MajorSubsystemVersion
=
_properties
.
MajorSubsystemVersion
;
...
...
@@ -422,8 +406,13 @@ private void FillInNtHeader(MetadataSizes metadataSizes, int mappedFieldDataStre
ntHeader
.
SizeOfHeapCommit
=
_properties
.
SizeOfHeapCommit
;
ntHeader
.
SizeOfCode
=
_textSection
.
SizeOfRawData
;
ntHeader
.
SizeOfInitializedData
=
_rdataSection
.
SizeOfRawData
+
_coverSection
.
SizeOfRawData
+
_sdataSection
.
SizeOfRawData
+
_tlsSection
.
SizeOfRawData
+
_resourceSection
.
SizeOfRawData
+
_relocSection
.
SizeOfRawData
;
// TODO: total size of all sections containing initialized data
ntHeader
.
SizeOfInitializedData
=
_resourceSection
.
SizeOfRawData
+
_relocSection
.
SizeOfRawData
;
ntHeader
.
SizeOfHeaders
=
BitArithmeticUtilities
.
Align
(
ComputeSizeOfPeHeaders
(),
_properties
.
FileAlignment
);
// TODO: last section:
ntHeader
.
SizeOfImage
=
BitArithmeticUtilities
.
Align
(
_relocSection
.
RelativeVirtualAddress
+
_relocSection
.
VirtualSize
,
0x2000
);
ntHeader
.
SizeOfUninitializedData
=
0
;
...
...
@@ -460,13 +449,6 @@ private void FillInNtHeader(MetadataSizes metadataSizes, int mappedFieldDataStre
_resourceSection
.
RelativeVirtualAddress
,
_resourceSection
.
VirtualSize
);
}
if
(
_tlsSection
.
SizeOfRawData
>
0
)
{
ntHeader
.
ThreadLocalStorageTable
=
new
DirectoryEntry
(
_tlsSection
.
RelativeVirtualAddress
,
_tlsSection
.
SizeOfRawData
);
}
}
private
void
FillInTextSectionHeader
(
MetadataSizes
metadataSizes
)
...
...
@@ -495,67 +477,7 @@ private void FillInTextSectionHeader(MetadataSizes metadataSizes)
private
void
FillInSectionHeaders
()
{
_rdataSection
=
new
SectionHeader
(
characteristics
:
SectionCharacteristics
.
MemRead
|
SectionCharacteristics
.
ContainsInitializedData
,
name
:
".rdata"
,
numberOfLinenumbers
:
0
,
numberOfRelocations
:
0
,
pointerToLinenumbers
:
0
,
pointerToRawData
:
_textSection
.
PointerToRawData
+
_textSection
.
SizeOfRawData
,
pointerToRelocations
:
0
,
relativeVirtualAddress
:
BitArithmeticUtilities
.
Align
(
_textSection
.
RelativeVirtualAddress
+
_textSection
.
VirtualSize
,
0x2000
),
sizeOfRawData
:
BitArithmeticUtilities
.
Align
(
_rdataWriter
.
Length
,
_properties
.
FileAlignment
),
virtualSize
:
_rdataWriter
.
Length
);
_sdataSection
=
new
SectionHeader
(
characteristics
:
SectionCharacteristics
.
MemRead
|
SectionCharacteristics
.
MemWrite
|
SectionCharacteristics
.
ContainsInitializedData
,
name
:
".sdata"
,
numberOfLinenumbers
:
0
,
numberOfRelocations
:
0
,
pointerToLinenumbers
:
0
,
pointerToRawData
:
_rdataSection
.
PointerToRawData
+
_rdataSection
.
SizeOfRawData
,
pointerToRelocations
:
0
,
relativeVirtualAddress
:
BitArithmeticUtilities
.
Align
(
_rdataSection
.
RelativeVirtualAddress
+
_rdataSection
.
VirtualSize
,
0x2000
),
sizeOfRawData
:
BitArithmeticUtilities
.
Align
(
_sdataWriter
.
Length
,
_properties
.
FileAlignment
),
virtualSize
:
_sdataWriter
.
Length
);
_coverSection
=
new
SectionHeader
(
characteristics
:
SectionCharacteristics
.
MemRead
|
SectionCharacteristics
.
MemWrite
|
SectionCharacteristics
.
MemNotPaged
|
SectionCharacteristics
.
ContainsInitializedData
,
name
:
".cover"
,
numberOfLinenumbers
:
0
,
numberOfRelocations
:
0
,
pointerToLinenumbers
:
0
,
pointerToRawData
:
_sdataSection
.
PointerToRawData
+
_sdataSection
.
SizeOfRawData
,
pointerToRelocations
:
0
,
relativeVirtualAddress
:
BitArithmeticUtilities
.
Align
(
_sdataSection
.
RelativeVirtualAddress
+
_sdataSection
.
VirtualSize
,
0x2000
),
sizeOfRawData
:
BitArithmeticUtilities
.
Align
(
_coverageDataWriter
.
Length
,
_properties
.
FileAlignment
),
virtualSize
:
_coverageDataWriter
.
Length
);
_tlsSection
=
new
SectionHeader
(
characteristics
:
SectionCharacteristics
.
MemRead
|
SectionCharacteristics
.
MemWrite
|
SectionCharacteristics
.
ContainsInitializedData
,
name
:
".tls"
,
numberOfLinenumbers
:
0
,
numberOfRelocations
:
0
,
pointerToLinenumbers
:
0
,
pointerToRawData
:
_coverSection
.
PointerToRawData
+
_coverSection
.
SizeOfRawData
,
pointerToRelocations
:
0
,
relativeVirtualAddress
:
BitArithmeticUtilities
.
Align
(
_coverSection
.
RelativeVirtualAddress
+
_coverSection
.
VirtualSize
,
0x2000
),
sizeOfRawData
:
BitArithmeticUtilities
.
Align
(
_tlsDataWriter
.
Length
,
_properties
.
FileAlignment
),
virtualSize
:
_tlsDataWriter
.
Length
);
int
resourcesRva
=
BitArithmeticUtilities
.
Align
(
_tlsSection
.
RelativeVirtualAddress
+
_tlsSection
.
VirtualSize
,
0x2000
);
int
resourcesRva
=
BitArithmeticUtilities
.
Align
(
_textSection
.
RelativeVirtualAddress
+
_textSection
.
VirtualSize
,
0x2000
);
int
sizeOfWin32Resources
=
this
.
ComputeSizeOfWin32Resources
(
resourcesRva
);
_resourceSection
=
new
SectionHeader
(
...
...
@@ -565,7 +487,7 @@ private void FillInSectionHeaders()
numberOfLinenumbers
:
0
,
numberOfRelocations
:
0
,
pointerToLinenumbers
:
0
,
pointerToRawData
:
_t
lsSection
.
PointerToRawData
+
_tls
Section
.
SizeOfRawData
,
pointerToRawData
:
_t
extSection
.
PointerToRawData
+
_text
Section
.
SizeOfRawData
,
pointerToRelocations
:
0
,
relativeVirtualAddress
:
resourcesRva
,
sizeOfRawData
:
BitArithmeticUtilities
.
Align
(
sizeOfWin32Resources
,
_properties
.
FileAlignment
),
...
...
@@ -1125,12 +1047,8 @@ private void WriteHeaders(Stream peStream, out long ntHeaderTimestampPosition)
// Section Headers
WriteSectionHeader
(
_textSection
,
writer
);
WriteSectionHeader
(
_rdataSection
,
writer
);
WriteSectionHeader
(
_sdataSection
,
writer
);
WriteSectionHeader
(
_coverSection
,
writer
);
WriteSectionHeader
(
_resourceSection
,
writer
);
WriteSectionHeader
(
_relocSection
,
writer
);
WriteSectionHeader
(
_tlsSection
,
writer
);
writer
.
WriteTo
(
peStream
);
_headerWriter
=
_emptyStream
;
...
...
@@ -1436,24 +1354,6 @@ private void WriteRuntimeStartupStub(Stream peStream)
writer
.
WriteTo
(
peStream
);
}
private
void
WriteCoverSection
(
Stream
peStream
)
{
peStream
.
Position
=
_coverSection
.
PointerToRawData
;
_coverageDataWriter
.
WriteTo
(
peStream
);
}
private
void
WriteRdataSection
(
Stream
peStream
)
{
peStream
.
Position
=
_rdataSection
.
PointerToRawData
;
_rdataWriter
.
WriteTo
(
peStream
);
}
private
void
WriteSdataSection
(
Stream
peStream
)
{
peStream
.
Position
=
_sdataSection
.
PointerToRawData
;
_sdataWriter
.
WriteTo
(
peStream
);
}
private
void
WriteRelocSection
(
Stream
peStream
)
{
if
(!
_properties
.
RequiresStartupStub
)
...
...
@@ -1500,11 +1400,5 @@ private void WriteResourceSection(Stream peStream)
peStream
.
WriteByte
(
0
);
}
}
private
void
WriteTlsSection
(
Stream
peStream
)
{
peStream
.
Position
=
_tlsSection
.
PointerToRawData
;
_tlsDataWriter
.
WriteTo
(
peStream
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录