Skip to content

Commit 47ad587

Browse files
committed
feat: Support --use-android-relr-tags
1 parent a236157 commit 47ad587

2 files changed

Lines changed: 68 additions & 6 deletions

File tree

libwild/src/args/elf.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub struct ElfArgs {
115115
pub(crate) max_page_size: Option<Alignment>,
116116
pub(crate) trace: bool,
117117
pack_dyn_relocs: PackDynRelocs,
118+
pub(crate) use_android_relr_tags: bool,
118119

119120
pub(crate) relocation_model: RelocationModel,
120121
pub(crate) should_output_executable: bool,
@@ -217,7 +218,6 @@ pub(super) const IGNORED_FLAGS: &[&str] = &[
217218
"fix-cortex-a53-835769",
218219
"fix-cortex-a53-843419",
219220
"discard-all",
220-
"use-android-relr-tags",
221221
"x", // alias for --discard-all
222222
];
223223

@@ -228,7 +228,6 @@ const DEFAULT_FLAGS: &[&str] = &[
228228
"no-add-needed",
229229
"discard-locals",
230230
"no-fatal-warnings",
231-
"no-use-android-relr-tags",
232231
];
233232
const DEFAULT_SHORT_FLAGS: &[&str] = &[
234233
"X", // alias for --discard-locals
@@ -292,6 +291,7 @@ impl Default for ElfArgs {
292291
hash_style: HashStyle::Both,
293292
trace: false,
294293
pack_dyn_relocs: PackDynRelocs::None,
294+
use_android_relr_tags: false,
295295

296296
unresolved_symbols: UnresolvedSymbols::ReportAll,
297297
error_unresolved_symbols: true,
@@ -1709,6 +1709,24 @@ fn setup_argument_parser() -> ArgumentParser<ElfArgs> {
17091709
Ok(())
17101710
});
17111711

1712+
parser
1713+
.declare()
1714+
.long("use-android-relr-tags")
1715+
.help("Use Android version of SHT_RELR and DT_RELR")
1716+
.execute(|args, _modifier_stack| {
1717+
args.use_android_relr_tags = true;
1718+
Ok(())
1719+
});
1720+
1721+
parser
1722+
.declare()
1723+
.long("no-use-android-relr-tags")
1724+
.help("Do not use Android version of SHT_RELR and DT_RELR (default)")
1725+
.execute(|args, _modifier_stack| {
1726+
args.use_android_relr_tags = false;
1727+
Ok(())
1728+
});
1729+
17121730
add_silently_ignored_flags(&mut parser);
17131731
add_default_flags(&mut parser);
17141732

libwild/src/elf_writer.rs

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4577,17 +4577,50 @@ const EPILOGUE_DYNAMIC_ENTRY_WRITERS: &[DynamicEntryWriter] = &[
45774577
}),
45784578
DynamicEntryWriter::optional(
45794579
object::elf::DT_RELR,
4580-
|inputs| inputs.has_data_in_section(output_section_id::RELR_DYN),
4580+
|inputs| {
4581+
inputs.has_data_in_section(output_section_id::RELR_DYN)
4582+
&& !has_android_relr_tags(inputs)
4583+
},
45814584
|inputs| inputs.vma_of_section(output_section_id::RELR_DYN),
45824585
),
45834586
DynamicEntryWriter::optional(
45844587
object::elf::DT_RELRSZ,
4585-
|inputs| inputs.has_data_in_section(output_section_id::RELR_DYN),
4588+
|inputs| {
4589+
inputs.has_data_in_section(output_section_id::RELR_DYN)
4590+
&& !has_android_relr_tags(inputs)
4591+
},
45864592
|inputs| inputs.size_of_section(output_section_id::RELR_DYN),
45874593
),
45884594
DynamicEntryWriter::optional(
45894595
object::elf::DT_RELRENT,
4590-
|inputs| inputs.has_data_in_section(output_section_id::RELR_DYN),
4596+
|inputs| {
4597+
inputs.has_data_in_section(output_section_id::RELR_DYN)
4598+
&& !has_android_relr_tags(inputs)
4599+
},
4600+
|_| elf::RELR_ENTRY_SIZE,
4601+
),
4602+
DynamicEntryWriter::optional(
4603+
// TODO(object): Not yet added
4604+
0x6fff_e000,
4605+
|inputs| {
4606+
inputs.has_data_in_section(output_section_id::RELR_DYN) && has_android_relr_tags(inputs)
4607+
},
4608+
|inputs| inputs.vma_of_section(output_section_id::RELR_DYN),
4609+
),
4610+
DynamicEntryWriter::optional(
4611+
// TODO(object): Not yet added
4612+
0x6fff_e001,
4613+
|inputs| {
4614+
inputs.has_data_in_section(output_section_id::RELR_DYN) && has_android_relr_tags(inputs)
4615+
},
4616+
|inputs| inputs.size_of_section(output_section_id::RELR_DYN),
4617+
),
4618+
DynamicEntryWriter::optional(
4619+
// TODO(object): Not yet added
4620+
0x6fff_e003,
4621+
|inputs| {
4622+
inputs.has_data_in_section(output_section_id::RELR_DYN) && has_android_relr_tags(inputs)
4623+
},
45914624
|_| elf::RELR_ENTRY_SIZE,
45924625
),
45934626
DynamicEntryWriter::optional(
@@ -4849,7 +4882,14 @@ fn write_section_headers(out: &mut [u8], layout: &ElfLayout) -> Result {
48494882
let entry = entries.next().unwrap();
48504883
let e = LittleEndian;
48514884
entry.sh_name.set(e, name_offset);
4852-
entry.sh_type.set(e, section_type.raw());
4885+
4886+
let sh_type = if layout.args().use_android_relr_tags && section_type == sht::RELR {
4887+
// TODO(object): Not yet added
4888+
0x6fffff00
4889+
} else {
4890+
section_type.raw()
4891+
};
4892+
entry.sh_type.set(e, sh_type);
48534893

48544894
// TODO: Sections are always uncompressed and the output compression is not supported yet.
48554895
entry.sh_flags.set(
@@ -5267,6 +5307,10 @@ fn has_rela_dyn(inputs: &DynamicEntryInputs) -> bool {
52675307
relative.mem_size > 0 || general.mem_size > 0
52685308
}
52695309

5310+
fn has_android_relr_tags(inputs: &DynamicEntryInputs) -> bool {
5311+
inputs.args.use_android_relr_tags
5312+
}
5313+
52705314
pub(crate) fn verify_resolution_allocation(
52715315
output_sections: &OutputSections<Elf>,
52725316
output_order: &OutputOrder,

0 commit comments

Comments
 (0)