Skip to content

Commit 329936b

Browse files
authored
Fix .ctors splitting for RELs (#126)
The ProDG hack in split_ctors_dtors caused the automated splitting of .ctors to be incorrect for RELs, by stripping relocatable function pointers out of the object. This patch checks for relocations, resolving both of the build failures observed in #125.
1 parent a9f34cb commit 329936b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/util/split.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use sanitise_file_name::sanitize_with_options;
1010
use tracing_attributes::instrument;
1111

1212
use crate::{
13-
analysis::{cfa::SectionAddress, read_address, read_u32},
13+
analysis::{cfa::SectionAddress, read_address, read_u32, relocation_target_for},
1414
obj::{
15-
ObjArchitecture, ObjInfo, ObjKind, ObjReloc, ObjRelocations, ObjSection, ObjSectionKind,
16-
ObjSplit, ObjSymbol, ObjSymbolFlagSet, ObjSymbolFlags, ObjSymbolKind, ObjSymbolScope,
17-
ObjUnit, SectionIndex, SymbolIndex,
15+
ObjArchitecture, ObjInfo, ObjKind, ObjReloc, ObjRelocKind, ObjRelocations, ObjSection,
16+
ObjSectionKind, ObjSplit, ObjSymbol, ObjSymbolFlagSet, ObjSymbolFlags, ObjSymbolKind,
17+
ObjSymbolScope, ObjUnit, SectionIndex, SymbolIndex,
1818
},
1919
util::{align_up, comment::MWComment, toposort::toposort},
2020
};
@@ -33,7 +33,9 @@ fn split_ctors_dtors(obj: &mut ObjInfo, start: SectionAddress, end: SectionAddre
3333

3434
while current_address < end {
3535
// ProDG hack when the end address is not known
36-
if matches!(read_u32(ctors_section, current_address.address), Some(0)) {
36+
if matches!(read_u32(ctors_section, current_address.address), Some(0))
37+
&& relocation_target_for(obj, current_address, Some(ObjRelocKind::Absolute))?.is_none()
38+
{
3739
while current_address < end {
3840
ensure!(
3941
matches!(read_u32(ctors_section, current_address.address), Some(0)),

0 commit comments

Comments
 (0)