Skip to content

Commit 9a6481d

Browse files
authored
Remove dead code in R2RPEBuilder (#115953)
1 parent 16a5d90 commit 9a6481d

File tree

1 file changed

+11
-97
lines changed

1 file changed

+11
-97
lines changed

src/coreclr/tools/aot/ILCompiler.ReadyToRun/ObjectWriter/R2RPEBuilder.cs

Lines changed: 11 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -28,52 +28,11 @@ public sealed class R2RPEBuilder : PEBuilder
2828
/// </summary>
2929
const int RVABitsToMatchFilePos = 16;
3030

31-
/// <summary>
32-
/// This structure describes how a particular section moved between the original MSIL
33-
/// and the output PE file. It holds beginning and end RVA of the input (MSIL) section
34-
/// and a delta between the input and output starting RVA of the section.
35-
/// </summary>
36-
struct SectionRVADelta
37-
{
38-
/// <summary>
39-
/// Starting RVA of the section in the input MSIL PE.
40-
/// </summary>
41-
public readonly int StartRVA;
42-
43-
/// <summary>
44-
/// End RVA (one plus the last RVA in the section) of the section in the input MSIL PE.
45-
/// </summary>
46-
public readonly int EndRVA;
47-
48-
/// <summary>
49-
/// Starting RVA of the section in the output PE minus its starting RVA in the input MSIL.
50-
/// </summary>
51-
public readonly int DeltaRVA;
52-
53-
/// <summary>
54-
/// Initialize the section RVA delta information.
55-
/// </summary>
56-
/// <param name="startRVA">Starting RVA of the section in the input MSIL</param>
57-
/// <param name="endRVA">End RVA of the section in the input MSIL</param>
58-
/// <param name="deltaRVA">Output RVA of the section minus input RVA of the section</param>
59-
public SectionRVADelta(int startRVA, int endRVA, int deltaRVA)
60-
{
61-
StartRVA = startRVA;
62-
EndRVA = endRVA;
63-
DeltaRVA = deltaRVA;
64-
}
65-
}
66-
6731
/// <summary>
6832
/// Name of the text section.
6933
/// </summary>
7034
public const string TextSectionName = ".text";
7135

72-
/// <summary>
73-
/// Name of the initialized data section.
74-
/// </summary>
75-
public const string SDataSectionName = ".sdata";
76-
7736
/// <summary>
7837
/// Name of the relocation section.
7938
/// </summary>
@@ -100,13 +59,6 @@ public SectionRVADelta(int startRVA, int endRVA, int deltaRVA)
10059
/// </summary>
10160
private Func<RuntimeFunctionsTableNode> _getRuntimeFunctionsTable;
10261

103-
/// <summary>
104-
/// For each copied section, we store its initial and end RVA in the source PE file
105-
/// and the RVA difference between the old and new file. We use this table to relocate
106-
/// directory entries in the PE file header.
107-
/// </summary>
108-
private List<SectionRVADelta> _sectionRvaDeltas;
109-
11062
private class SerializedSectionData
11163
{
11264
/// <summary>
@@ -194,7 +146,6 @@ public R2RPEBuilder(
194146
{
195147
_target = target;
196148
_getRuntimeFunctionsTable = getRuntimeFunctionsTable;
197-
_sectionRvaDeltas = new List<SectionRVADelta>();
198149

199150
_sectionBuilder = new SectionBuilder(target);
200151

@@ -210,16 +161,13 @@ public R2RPEBuilder(
210161
_sectionBuilder.SetDllNameForExportDirectoryTable(outputFileSimpleName);
211162
}
212163

213-
if (_sectionBuilder.FindSection(R2RPEBuilder.RelocSectionName) == null)
214-
{
215-
// Always inject the relocation section to the end of section list
216-
_sectionBuilder.AddSection(
217-
R2RPEBuilder.RelocSectionName,
218-
SectionCharacteristics.ContainsInitializedData |
219-
SectionCharacteristics.MemRead |
220-
SectionCharacteristics.MemDiscardable,
221-
PEHeaderConstants.SectionAlignment);
222-
}
164+
// Always inject the relocation section to the end of section list
165+
_sectionBuilder.AddSection(
166+
R2RPEBuilder.RelocSectionName,
167+
SectionCharacteristics.ContainsInitializedData |
168+
SectionCharacteristics.MemRead |
169+
SectionCharacteristics.MemDiscardable,
170+
PEHeaderConstants.SectionAlignment);
223171

224172
List<SerializedSectionData> sectionData = new List<SerializedSectionData>();
225173
foreach (SectionInfo sectionInfo in _sectionBuilder.GetSections())
@@ -353,7 +301,7 @@ public void AddSections(OutputInfoBuilder outputInfoBuilder)
353301
sizeof(int) + // SizeOfUninitializedData
354302
sizeof(int) + // AddressOfEntryPoint
355303
sizeof(int) + // BaseOfCode
356-
sizeof(long); // PE32: BaseOfData (int), ImageBase (int)
304+
sizeof(long); // PE32: BaseOfData (int), ImageBase (int)
357305
// PE32+: ImageBase (long)
358306
const int OffsetOfChecksum = OffsetOfSectionAlign +
359307
sizeof(int) + // SectionAlignment
@@ -371,7 +319,7 @@ public void AddSections(OutputInfoBuilder outputInfoBuilder)
371319
const int OffsetOfSizeOfImage = OffsetOfChecksum - 2 * sizeof(int); // SizeOfHeaders, SizeOfImage
372320

373321
const int SectionHeaderNameSize = 8;
374-
const int SectionHeaderVirtualSize = SectionHeaderNameSize; // VirtualSize follows
322+
const int SectionHeaderVirtualSize = SectionHeaderNameSize; // VirtualSize follows
375323
const int SectionHeaderRVAOffset = SectionHeaderVirtualSize + sizeof(int); // RVA Offset follows VirtualSize + 4 bytes VirtualSize
376324
const int SectionHeaderSizeOfRawData = SectionHeaderRVAOffset + sizeof(int); // SizeOfRawData follows RVA
377325
const int SectionHeaderPointerToRawDataOffset = SectionHeaderSizeOfRawData + sizeof(int); // PointerToRawData immediately follows the SizeOfRawData
@@ -385,7 +333,7 @@ public void AddSections(OutputInfoBuilder outputInfoBuilder)
385333
sizeof(int) + // PointerToRelocations
386334
sizeof(int) + // PointerToLineNumbers
387335
sizeof(short) + // NumberOfRelocations
388-
sizeof(short) + // NumberOfLineNumbers
336+
sizeof(short) + // NumberOfLineNumbers
389337
sizeof(int); // SectionCharacteristics
390338

391339
/// <summary>
@@ -538,42 +486,8 @@ protected override PEDirectoriesBuilder GetDirectories()
538486
size: runtimeFunctionsTable.TableSizeExcludingSentinel);
539487
}
540488
}
541-
542-
return builder;
543-
}
544489

545-
/// <summary>
546-
/// Relocate a single directory entry.
547-
/// </summary>
548-
/// <param name="entry">Directory entry to allocate</param>
549-
/// <returns>Relocated directory entry</returns>
550-
public DirectoryEntry RelocateDirectoryEntry(DirectoryEntry entry)
551-
{
552-
return new DirectoryEntry(RelocateRVA(entry.RelativeVirtualAddress), entry.Size);
553-
}
554-
555-
/// <summary>
556-
/// Relocate a given RVA using the section offset table produced during section serialization.
557-
/// </summary>
558-
/// <param name="rva">RVA to relocate</param>
559-
/// <returns>Relocated RVA</returns>
560-
private int RelocateRVA(int rva)
561-
{
562-
if (rva == 0)
563-
{
564-
// Zero RVA is normally used as NULL
565-
return rva;
566-
}
567-
foreach (SectionRVADelta sectionRvaDelta in _sectionRvaDeltas)
568-
{
569-
if (rva >= sectionRvaDelta.StartRVA && rva < sectionRvaDelta.EndRVA)
570-
{
571-
// We found the input section holding the RVA, apply its specific delt (output RVA - input RVA).
572-
return rva + sectionRvaDelta.DeltaRVA;
573-
}
574-
}
575-
Debug.Fail("RVA is not within any of the input sections - output PE may be inconsistent");
576-
return rva;
490+
return builder;
577491
}
578492

579493
/// <summary>

0 commit comments

Comments
 (0)