@@ -290,36 +290,35 @@ func (t *peStringTable) write() {
290
290
291
291
// peSection represents section from COFF section table.
292
292
type peSection struct {
293
- name string
294
- shortName string
295
- index int // one-based index into the Section Table
296
- // TODO: change all these names to start with small letters
297
- VirtualSize uint32
298
- VirtualAddress uint32
299
- SizeOfRawData uint32
300
- PointerToRawData uint32
301
- PointerToRelocations uint32
302
- NumberOfRelocations uint16
303
- Characteristics uint32
293
+ name string
294
+ shortName string
295
+ index int // one-based index into the Section Table
296
+ virtualSize uint32
297
+ virtualAddress uint32
298
+ sizeOfRawData uint32
299
+ pointerToRawData uint32
300
+ pointerToRelocations uint32
301
+ numberOfRelocations uint16
302
+ characteristics uint32
304
303
}
305
304
306
305
// checkOffset verifies COFF section sect offset in the file.
307
306
func (sect * peSection ) checkOffset (off int64 ) {
308
- if off != int64 (sect .PointerToRawData ) {
309
- Errorf (nil , "%s.PointerToRawData = %#x, want %#x" , sect .name , uint64 (int64 (sect .PointerToRawData )), uint64 (off ))
307
+ if off != int64 (sect .pointerToRawData ) {
308
+ Errorf (nil , "%s.PointerToRawData = %#x, want %#x" , sect .name , uint64 (int64 (sect .pointerToRawData )), uint64 (off ))
310
309
errorexit ()
311
310
}
312
311
}
313
312
314
313
// checkSegment verifies COFF section sect matches address
315
314
// and file offset provided in segment seg.
316
315
func (sect * peSection ) checkSegment (seg * Segment ) {
317
- if seg .Vaddr - PEBASE != uint64 (sect .VirtualAddress ) {
318
- Errorf (nil , "%s.VirtualAddress = %#x, want %#x" , sect .name , uint64 (int64 (sect .VirtualAddress )), uint64 (int64 (seg .Vaddr - PEBASE )))
316
+ if seg .Vaddr - PEBASE != uint64 (sect .virtualAddress ) {
317
+ Errorf (nil , "%s.VirtualAddress = %#x, want %#x" , sect .name , uint64 (int64 (sect .virtualAddress )), uint64 (int64 (seg .Vaddr - PEBASE )))
319
318
errorexit ()
320
319
}
321
- if seg .Fileoff != uint64 (sect .PointerToRawData ) {
322
- Errorf (nil , "%s.PointerToRawData = %#x, want %#x" , sect .name , uint64 (int64 (sect .PointerToRawData )), uint64 (int64 (seg .Fileoff )))
320
+ if seg .Fileoff != uint64 (sect .pointerToRawData ) {
321
+ Errorf (nil , "%s.PointerToRawData = %#x, want %#x" , sect .name , uint64 (int64 (sect .pointerToRawData )), uint64 (int64 (seg .Fileoff )))
323
322
errorexit ()
324
323
}
325
324
}
@@ -328,21 +327,21 @@ func (sect *peSection) checkSegment(seg *Segment) {
328
327
// as necessary to make section sect.SizeOfRawData bytes long.
329
328
// It assumes that n bytes are already written to the file.
330
329
func (sect * peSection ) pad (n uint32 ) {
331
- strnput ("" , int (sect .SizeOfRawData - n ))
330
+ strnput ("" , int (sect .sizeOfRawData - n ))
332
331
}
333
332
334
333
// write writes COFF section sect into the output file.
335
334
func (sect * peSection ) write () error {
336
335
h := pe.SectionHeader32 {
337
- VirtualSize : sect .VirtualSize ,
338
- SizeOfRawData : sect .SizeOfRawData ,
339
- PointerToRawData : sect .PointerToRawData ,
340
- PointerToRelocations : sect .PointerToRelocations ,
341
- NumberOfRelocations : sect .NumberOfRelocations ,
342
- Characteristics : sect .Characteristics ,
336
+ VirtualSize : sect .virtualSize ,
337
+ SizeOfRawData : sect .sizeOfRawData ,
338
+ PointerToRawData : sect .pointerToRawData ,
339
+ PointerToRelocations : sect .pointerToRelocations ,
340
+ NumberOfRelocations : sect .numberOfRelocations ,
341
+ Characteristics : sect .characteristics ,
343
342
}
344
343
if Linkmode != LinkExternal {
345
- h .VirtualAddress = sect .VirtualAddress
344
+ h .VirtualAddress = sect .virtualAddress
346
345
}
347
346
copy (h .Name [:], sect .shortName )
348
347
return binary .Write (& coutbuf , binary .LittleEndian , h )
@@ -353,7 +352,7 @@ func (sect *peSection) write() error {
353
352
// This updates the corresponding PE section table entry
354
353
// with the relocation offset and count.
355
354
func (sect * peSection ) emitRelocations (relocfn func () int ) {
356
- sect .PointerToRelocations = uint32 (coutbuf .Offset ())
355
+ sect .pointerToRelocations = uint32 (coutbuf .Offset ())
357
356
// first entry: extended relocs
358
357
Lputl (0 ) // placeholder for number of relocation + 1
359
358
Lputl (0 )
@@ -362,16 +361,16 @@ func (sect *peSection) emitRelocations(relocfn func() int) {
362
361
n := relocfn () + 1
363
362
364
363
cpos := coutbuf .Offset ()
365
- Cseek (int64 (sect .PointerToRelocations ))
364
+ Cseek (int64 (sect .pointerToRelocations ))
366
365
Lputl (uint32 (n ))
367
366
Cseek (cpos )
368
367
if n > 0x10000 {
369
368
n = 0x10000
370
- sect .Characteristics |= IMAGE_SCN_LNK_NRELOC_OVFL
369
+ sect .characteristics |= IMAGE_SCN_LNK_NRELOC_OVFL
371
370
} else {
372
- sect .PointerToRelocations += 10 // skip the extend reloc entry
371
+ sect .pointerToRelocations += 10 // skip the extend reloc entry
373
372
}
374
- sect .NumberOfRelocations = uint16 (n - 1 )
373
+ sect .numberOfRelocations = uint16 (n - 1 )
375
374
}
376
375
377
376
// peFile is used to build COFF file.
@@ -395,14 +394,14 @@ func (f *peFile) addSection(name string, sectsize int, filesize int) *peSection
395
394
name : name ,
396
395
shortName : name ,
397
396
index : len (f .sections ) + 1 ,
398
- VirtualSize : uint32 (sectsize ),
399
- VirtualAddress : f .nextSectOffset ,
400
- PointerToRawData : f .nextFileOffset ,
397
+ virtualSize : uint32 (sectsize ),
398
+ virtualAddress : f .nextSectOffset ,
399
+ pointerToRawData : f .nextFileOffset ,
401
400
}
402
401
f .nextSectOffset = uint32 (Rnd (int64 (f .nextSectOffset )+ int64 (sectsize ), PESECTALIGN ))
403
402
if filesize > 0 {
404
- sect .SizeOfRawData = uint32 (Rnd (int64 (filesize ), PEFILEALIGN ))
405
- f .nextFileOffset += sect .SizeOfRawData
403
+ sect .sizeOfRawData = uint32 (Rnd (int64 (filesize ), PEFILEALIGN ))
404
+ f .nextFileOffset += sect .sizeOfRawData
406
405
}
407
406
f .sections = append (f .sections , sect )
408
407
return sect
@@ -424,7 +423,7 @@ func (f *peFile) addDWARFSection(name string, size int) *peSection {
424
423
off := f .stringTable .add (name )
425
424
h := f .addSection (name , size , size )
426
425
h .shortName = fmt .Sprintf ("/%d" , off )
427
- h .Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE
426
+ h .characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE
428
427
return h
429
428
}
430
429
@@ -439,8 +438,8 @@ func (f *peFile) addDWARF() {
439
438
for _ , sect := range Segdwarf .Sections {
440
439
h := f .addDWARFSection (sect .Name , int (sect .Length ))
441
440
fileoff := sect .Vaddr - Segdwarf .Vaddr + Segdwarf .Fileoff
442
- if uint64 (h .PointerToRawData ) != fileoff {
443
- Exitf ("%s.PointerToRawData = %#x, want %#x" , sect .Name , h .PointerToRawData , fileoff )
441
+ if uint64 (h .pointerToRawData ) != fileoff {
442
+ Exitf ("%s.PointerToRawData = %#x, want %#x" , sect .Name , h .pointerToRawData , fileoff )
444
443
}
445
444
}
446
445
}
@@ -462,9 +461,9 @@ func (f *peFile) addInitArray(ctxt *Link) *peSection {
462
461
size = 8
463
462
}
464
463
sect := f .addSection (".ctors" , size , size )
465
- sect .Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
466
- sect .SizeOfRawData = uint32 (size )
467
- Cseek (int64 (sect .PointerToRawData ))
464
+ sect .characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
465
+ sect .sizeOfRawData = uint32 (size )
466
+ Cseek (int64 (sect .pointerToRawData ))
468
467
sect .checkOffset (coutbuf .Offset ())
469
468
470
469
init_entry := ctxt .Syms .Lookup (* flagEntrySymbol , 0 )
@@ -698,7 +697,7 @@ func (f *peFile) writeSymbolTableAndStringTable(ctxt *Link) {
698
697
// We do not really need .symtab for go.o, and if we have one, ld
699
698
// will also include it in the exe, and that will confuse windows.
700
699
h = f .addSection (".symtab" , size , size )
701
- h .Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE
700
+ h .characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE
702
701
h .checkOffset (f .symtabOffset )
703
702
}
704
703
@@ -758,26 +757,26 @@ func (f *peFile) writeOptionalHeader(ctxt *Link) {
758
757
oh64 .Magic = 0x20b // PE32+
759
758
} else {
760
759
oh .Magic = 0x10b // PE32
761
- oh .BaseOfData = f .dataSect .VirtualAddress
760
+ oh .BaseOfData = f .dataSect .virtualAddress
762
761
}
763
762
764
763
// Fill out both oh64 and oh. We only use one. Oh well.
765
764
oh64 .MajorLinkerVersion = 3
766
765
oh .MajorLinkerVersion = 3
767
766
oh64 .MinorLinkerVersion = 0
768
767
oh .MinorLinkerVersion = 0
769
- oh64 .SizeOfCode = f .textSect .SizeOfRawData
770
- oh .SizeOfCode = f .textSect .SizeOfRawData
771
- oh64 .SizeOfInitializedData = f .dataSect .SizeOfRawData
772
- oh .SizeOfInitializedData = f .dataSect .SizeOfRawData
768
+ oh64 .SizeOfCode = f .textSect .sizeOfRawData
769
+ oh .SizeOfCode = f .textSect .sizeOfRawData
770
+ oh64 .SizeOfInitializedData = f .dataSect .sizeOfRawData
771
+ oh .SizeOfInitializedData = f .dataSect .sizeOfRawData
773
772
oh64 .SizeOfUninitializedData = 0
774
773
oh .SizeOfUninitializedData = 0
775
774
if Linkmode != LinkExternal {
776
775
oh64 .AddressOfEntryPoint = uint32 (Entryvalue (ctxt ) - PEBASE )
777
776
oh .AddressOfEntryPoint = uint32 (Entryvalue (ctxt ) - PEBASE )
778
777
}
779
- oh64 .BaseOfCode = f .textSect .VirtualAddress
780
- oh .BaseOfCode = f .textSect .VirtualAddress
778
+ oh64 .BaseOfCode = f .textSect .virtualAddress
779
+ oh .BaseOfCode = f .textSect .virtualAddress
781
780
oh64 .ImageBase = PEBASE
782
781
oh .ImageBase = PEBASE
783
782
oh64 .SectionAlignment = uint32 (PESECTALIGN )
@@ -1096,15 +1095,15 @@ func addimports(ctxt *Link, datsect *peSection) {
1096
1095
n = uint64 (coutbuf .Offset ()) - uint64 (startoff )
1097
1096
1098
1097
isect := pefile .addSection (".idata" , int (n ), int (n ))
1099
- isect .Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE
1098
+ isect .characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE
1100
1099
isect .checkOffset (startoff )
1101
1100
isect .pad (uint32 (n ))
1102
1101
endoff := coutbuf .Offset ()
1103
1102
1104
1103
// write FirstThunks (allocated in .data section)
1105
- ftbase := uint64 (dynamic .Value ) - uint64 (datsect .VirtualAddress ) - PEBASE
1104
+ ftbase := uint64 (dynamic .Value ) - uint64 (datsect .virtualAddress ) - PEBASE
1106
1105
1107
- Cseek (int64 (uint64 (datsect .PointerToRawData ) + ftbase ))
1106
+ Cseek (int64 (uint64 (datsect .pointerToRawData ) + ftbase ))
1108
1107
for d := dr ; d != nil ; d = d .next {
1109
1108
for m = d .ms ; m != nil ; m = m .next {
1110
1109
if pe64 != 0 {
@@ -1125,11 +1124,11 @@ func addimports(ctxt *Link, datsect *peSection) {
1125
1124
Cseek (startoff )
1126
1125
1127
1126
for d := dr ; d != nil ; d = d .next {
1128
- Lputl (uint32 (uint64 (isect .VirtualAddress ) + oftbase + d .thunkoff ))
1127
+ Lputl (uint32 (uint64 (isect .virtualAddress ) + oftbase + d .thunkoff ))
1129
1128
Lputl (0 )
1130
1129
Lputl (0 )
1131
- Lputl (uint32 (uint64 (isect .VirtualAddress ) + d .nameoff ))
1132
- Lputl (uint32 (uint64 (datsect .VirtualAddress ) + ftbase + d .thunkoff ))
1130
+ Lputl (uint32 (uint64 (isect .virtualAddress ) + d .nameoff ))
1131
+ Lputl (uint32 (uint64 (datsect .virtualAddress ) + ftbase + d .thunkoff ))
1133
1132
}
1134
1133
1135
1134
Lputl (0 ) //end
@@ -1139,8 +1138,8 @@ func addimports(ctxt *Link, datsect *peSection) {
1139
1138
Lputl (0 )
1140
1139
1141
1140
// update data directory
1142
- pefile .dataDirectory [IMAGE_DIRECTORY_ENTRY_IMPORT ].VirtualAddress = isect .VirtualAddress
1143
- pefile .dataDirectory [IMAGE_DIRECTORY_ENTRY_IMPORT ].Size = isect .VirtualSize
1141
+ pefile .dataDirectory [IMAGE_DIRECTORY_ENTRY_IMPORT ].VirtualAddress = isect .virtualAddress
1142
+ pefile .dataDirectory [IMAGE_DIRECTORY_ENTRY_IMPORT ].Size = isect .virtualSize
1144
1143
pefile .dataDirectory [IMAGE_DIRECTORY_ENTRY_IAT ].VirtualAddress = uint32 (dynamic .Value - PEBASE )
1145
1144
pefile .dataDirectory [IMAGE_DIRECTORY_ENTRY_IAT ].Size = uint32 (dynamic .Size )
1146
1145
@@ -1184,11 +1183,11 @@ func addexports(ctxt *Link) {
1184
1183
}
1185
1184
1186
1185
sect := pefile .addSection (".edata" , size , size )
1187
- sect .Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
1186
+ sect .characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
1188
1187
sect .checkOffset (coutbuf .Offset ())
1189
- va := int (sect .VirtualAddress )
1188
+ va := int (sect .virtualAddress )
1190
1189
pefile .dataDirectory [IMAGE_DIRECTORY_ENTRY_EXPORT ].VirtualAddress = uint32 (va )
1191
- pefile .dataDirectory [IMAGE_DIRECTORY_ENTRY_EXPORT ].Size = sect .VirtualSize
1190
+ pefile .dataDirectory [IMAGE_DIRECTORY_ENTRY_EXPORT ].Size = sect .virtualSize
1192
1191
1193
1192
vaName := va + binary .Size (& e ) + nexport * 4
1194
1193
vaAddr := va + binary .Size (& e )
@@ -1260,7 +1259,7 @@ func addpersrc(ctxt *Link) {
1260
1259
}
1261
1260
1262
1261
h := pefile .addSection (".rsrc" , int (rsrcsym .Size ), int (rsrcsym .Size ))
1263
- h .Characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_INITIALIZED_DATA
1262
+ h .characteristics = IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_CNT_INITIALIZED_DATA
1264
1263
h .checkOffset (coutbuf .Offset ())
1265
1264
1266
1265
// relocation
@@ -1270,7 +1269,7 @@ func addpersrc(ctxt *Link) {
1270
1269
for ri := 0 ; ri < len (rsrcsym .R ); ri ++ {
1271
1270
r = & rsrcsym .R [ri ]
1272
1271
p = rsrcsym .P [r .Off :]
1273
- val = uint32 (int64 (h .VirtualAddress ) + r .Add )
1272
+ val = uint32 (int64 (h .virtualAddress ) + r .Add )
1274
1273
1275
1274
// 32-bit little-endian
1276
1275
p [0 ] = byte (val )
@@ -1284,9 +1283,9 @@ func addpersrc(ctxt *Link) {
1284
1283
h .pad (uint32 (rsrcsym .Size ))
1285
1284
1286
1285
// update data directory
1287
- pefile .dataDirectory [IMAGE_DIRECTORY_ENTRY_RESOURCE ].VirtualAddress = h .VirtualAddress
1286
+ pefile .dataDirectory [IMAGE_DIRECTORY_ENTRY_RESOURCE ].VirtualAddress = h .virtualAddress
1288
1287
1289
- pefile .dataDirectory [IMAGE_DIRECTORY_ENTRY_RESOURCE ].Size = h .VirtualSize
1288
+ pefile .dataDirectory [IMAGE_DIRECTORY_ENTRY_RESOURCE ].Size = h .virtualSize
1290
1289
}
1291
1290
1292
1291
func Asmbpe (ctxt * Link ) {
@@ -1297,30 +1296,30 @@ func Asmbpe(ctxt *Link) {
1297
1296
}
1298
1297
1299
1298
t := pefile .addSection (".text" , int (Segtext .Length ), int (Segtext .Length ))
1300
- t .Characteristics = IMAGE_SCN_CNT_CODE | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ
1299
+ t .characteristics = IMAGE_SCN_CNT_CODE | IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_MEM_READ
1301
1300
if Linkmode == LinkExternal {
1302
1301
// some data symbols (e.g. masks) end up in the .text section, and they normally
1303
1302
// expect larger alignment requirement than the default text section alignment.
1304
- t .Characteristics |= IMAGE_SCN_ALIGN_32BYTES
1303
+ t .characteristics |= IMAGE_SCN_ALIGN_32BYTES
1305
1304
}
1306
1305
t .checkSegment (& Segtext )
1307
1306
pefile .textSect = t
1308
1307
1309
1308
var d * peSection
1310
1309
if Linkmode != LinkExternal {
1311
1310
d = pefile .addSection (".data" , int (Segdata .Length ), int (Segdata .Filelen ))
1312
- d .Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE
1311
+ d .characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE
1313
1312
d .checkSegment (& Segdata )
1314
1313
pefile .dataSect = d
1315
1314
} else {
1316
1315
d = pefile .addSection (".data" , int (Segdata .Filelen ), int (Segdata .Filelen ))
1317
- d .Characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_ALIGN_32BYTES
1316
+ d .characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_ALIGN_32BYTES
1318
1317
d .checkSegment (& Segdata )
1319
1318
pefile .dataSect = d
1320
1319
1321
1320
b := pefile .addSection (".bss" , int (Segdata .Length - Segdata .Filelen ), 0 )
1322
- b .Characteristics = IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_ALIGN_32BYTES
1323
- b .PointerToRawData = 0
1321
+ b .characteristics = IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE | IMAGE_SCN_ALIGN_32BYTES
1322
+ b .pointerToRawData = 0
1324
1323
pefile .bssSect = b
1325
1324
}
1326
1325
0 commit comments