@@ -32,6 +32,7 @@ use crate::layout::PreludeLayout;
32
32
use crate :: layout:: Resolution ;
33
33
use crate :: layout:: ResolutionFlags ;
34
34
use crate :: layout:: Section ;
35
+ use crate :: layout:: StringOffsetCache ;
35
36
use crate :: layout:: SymbolCopyInfo ;
36
37
use crate :: output_section_id;
37
38
use crate :: output_section_id:: OrderEvent ;
@@ -1113,13 +1114,14 @@ impl<'out> ObjectLayout<'out> {
1113
1114
) -> Result {
1114
1115
let _span = debug_span ! ( "write_file" , filename = ?self . input. file. filename) . entered ( ) ;
1115
1116
let _file_span = layout. args ( ) . trace_span_for_file ( self . file_id ) ;
1117
+ let mut string_offset_cache = StringOffsetCache :: new ( & layout. output_sections ) ;
1116
1118
for sec in & self . sections {
1117
1119
match sec {
1118
1120
SectionSlot :: Loaded ( sec) => {
1119
1121
self . write_section ( layout, sec, buffers, table_writer) ?
1120
1122
}
1121
1123
SectionSlot :: LoadedDebugInfo ( sec) => {
1122
- self . write_debug_section ( layout, sec, buffers) ?;
1124
+ self . write_debug_section ( layout, sec, buffers, & mut string_offset_cache ) ?;
1123
1125
}
1124
1126
SectionSlot :: EhFrameData ( section_index) => {
1125
1127
self . write_eh_frame_data ( * section_index, layout, table_writer) ?;
@@ -1192,9 +1194,10 @@ impl<'out> ObjectLayout<'out> {
1192
1194
layout : & Layout ,
1193
1195
sec : & Section ,
1194
1196
buffers : & mut OutputSectionPartMap < & mut [ u8 ] > ,
1197
+ string_offset_cache : & mut StringOffsetCache ,
1195
1198
) -> Result {
1196
1199
let out = self . write_section_raw ( layout, sec, buffers) ?;
1197
- self . apply_debug_relocations ( out, sec, layout)
1200
+ self . apply_debug_relocations ( out, sec, layout, string_offset_cache )
1198
1201
. with_context ( || {
1199
1202
format ! (
1200
1203
"Failed to apply relocations in section `{}` of {}" ,
@@ -1336,6 +1339,7 @@ impl<'out> ObjectLayout<'out> {
1336
1339
layout,
1337
1340
out,
1338
1341
table_writer,
1342
+ & mut StringOffsetCache :: no_caching ( ) ,
1339
1343
)
1340
1344
. with_context ( || {
1341
1345
format ! (
@@ -1352,6 +1356,7 @@ impl<'out> ObjectLayout<'out> {
1352
1356
out : & mut [ u8 ] ,
1353
1357
section : & Section ,
1354
1358
layout : & Layout ,
1359
+ string_offset_cache : & mut StringOffsetCache ,
1355
1360
) -> Result {
1356
1361
let object_section = self . object . section ( section. index ) ?;
1357
1362
let section_name = self . object . section_name ( object_section) ?;
@@ -1375,13 +1380,21 @@ impl<'out> ObjectLayout<'out> {
1375
1380
. fetch_add ( relocations. len ( ) as u64 , Relaxed ) ;
1376
1381
for rel in relocations {
1377
1382
let offset_in_section = rel. r_offset . get ( LittleEndian ) ;
1378
- apply_debug_relocation ( self , offset_in_section, rel, layout, tombstone_value, out)
1379
- . with_context ( || {
1380
- format ! (
1381
- "Failed to apply {} at offset 0x{offset_in_section:x}" ,
1382
- self . display_relocation( rel, layout)
1383
- )
1384
- } ) ?;
1383
+ apply_debug_relocation (
1384
+ self ,
1385
+ offset_in_section,
1386
+ rel,
1387
+ layout,
1388
+ tombstone_value,
1389
+ out,
1390
+ string_offset_cache,
1391
+ )
1392
+ . with_context ( || {
1393
+ format ! (
1394
+ "Failed to apply {} at offset 0x{offset_in_section:x}" ,
1395
+ self . display_relocation( rel, layout)
1396
+ )
1397
+ } ) ?;
1385
1398
}
1386
1399
Ok ( ( ) )
1387
1400
}
@@ -1506,6 +1519,7 @@ impl<'out> ObjectLayout<'out> {
1506
1519
layout,
1507
1520
entry_out,
1508
1521
table_writer,
1522
+ & mut StringOffsetCache :: no_caching ( ) ,
1509
1523
)
1510
1524
. with_context ( || {
1511
1525
format ! (
@@ -1600,6 +1614,7 @@ fn apply_relocation(
1600
1614
layout : & Layout ,
1601
1615
out : & mut [ u8 ] ,
1602
1616
table_writer : & mut TableWriter ,
1617
+ string_offset_cache : & mut StringOffsetCache ,
1603
1618
) -> Result < RelocationModifier > {
1604
1619
let section_address = section_info. section_address ;
1605
1620
let place = section_address + offset_in_section;
@@ -1659,6 +1674,7 @@ fn apply_relocation(
1659
1674
object_layout,
1660
1675
& layout. merged_strings ,
1661
1676
& layout. merged_string_start_addresses ,
1677
+ string_offset_cache,
1662
1678
) ?
1663
1679
. wrapping_sub ( place)
1664
1680
. wrapping_sub ( rel_info. byte_size as u64 ) ,
@@ -1721,6 +1737,7 @@ fn apply_debug_relocation(
1721
1737
layout : & Layout ,
1722
1738
section_tombstone_value : u64 ,
1723
1739
out : & mut [ u8 ] ,
1740
+ string_offset_cache : & mut StringOffsetCache ,
1724
1741
) -> Result < ( ) > {
1725
1742
let e = LittleEndian ;
1726
1743
let symbol_index = rel
@@ -1749,6 +1766,7 @@ fn apply_debug_relocation(
1749
1766
object_layout,
1750
1767
& layout. merged_strings ,
1751
1768
& layout. merged_string_start_addresses ,
1769
+ string_offset_cache,
1752
1770
) ?,
1753
1771
RelocationKind :: DtpOff => resolution
1754
1772
. value ( )
@@ -1766,6 +1784,7 @@ fn apply_debug_relocation(
1766
1784
& layout. merged_strings ,
1767
1785
& layout. merged_string_start_addresses ,
1768
1786
false ,
1787
+ string_offset_cache,
1769
1788
) ?
1770
1789
. context ( "Cannot get merged string offset for a debug info section" ) ?,
1771
1790
SectionSlot :: Discard | SectionSlot :: Unloaded ( ..) => section_tombstone_value,
@@ -1814,6 +1833,7 @@ fn write_absolute_relocation(
1814
1833
object_layout,
1815
1834
& layout. merged_strings ,
1816
1835
& layout. merged_string_start_addresses ,
1836
+ & mut StringOffsetCache :: no_caching ( ) ,
1817
1837
)
1818
1838
}
1819
1839
}
0 commit comments