Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions libwild/src/args/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub struct ElfArgs {
pub(crate) max_page_size: Option<Alignment>,
pub(crate) trace: bool,
pack_dyn_relocs: PackDynRelocs,
pub(crate) use_android_relr_tags: bool,

pub(crate) relocation_model: RelocationModel,
pub(crate) should_output_executable: bool,
Expand Down Expand Up @@ -217,7 +218,6 @@ pub(super) const IGNORED_FLAGS: &[&str] = &[
"fix-cortex-a53-835769",
"fix-cortex-a53-843419",
"discard-all",
"use-android-relr-tags",
"x", // alias for --discard-all
];

Expand All @@ -228,7 +228,6 @@ const DEFAULT_FLAGS: &[&str] = &[
"no-add-needed",
"discard-locals",
"no-fatal-warnings",
"no-use-android-relr-tags",
];
const DEFAULT_SHORT_FLAGS: &[&str] = &[
"X", // alias for --discard-locals
Expand Down Expand Up @@ -292,6 +291,7 @@ impl Default for ElfArgs {
hash_style: HashStyle::Both,
trace: false,
pack_dyn_relocs: PackDynRelocs::None,
use_android_relr_tags: false,

unresolved_symbols: UnresolvedSymbols::ReportAll,
error_unresolved_symbols: true,
Expand Down Expand Up @@ -1709,6 +1709,24 @@ fn setup_argument_parser() -> ArgumentParser<ElfArgs> {
Ok(())
});

parser
.declare()
.long("use-android-relr-tags")
.help("Use Android version of SHT_RELR and DT_RELR")
.execute(|args, _modifier_stack| {
args.use_android_relr_tags = true;
Ok(())
});

parser
.declare()
.long("no-use-android-relr-tags")
.help("Do not use Android version of SHT_RELR and DT_RELR (default)")
.execute(|args, _modifier_stack| {
args.use_android_relr_tags = false;
Ok(())
});

add_silently_ignored_flags(&mut parser);
add_default_flags(&mut parser);

Expand Down
52 changes: 48 additions & 4 deletions libwild/src/elf_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4577,17 +4577,50 @@ const EPILOGUE_DYNAMIC_ENTRY_WRITERS: &[DynamicEntryWriter] = &[
}),
DynamicEntryWriter::optional(
object::elf::DT_RELR,
|inputs| inputs.has_data_in_section(output_section_id::RELR_DYN),
|inputs| {
inputs.has_data_in_section(output_section_id::RELR_DYN)
&& !has_android_relr_tags(inputs)
},
|inputs| inputs.vma_of_section(output_section_id::RELR_DYN),
),
DynamicEntryWriter::optional(
object::elf::DT_RELRSZ,
|inputs| inputs.has_data_in_section(output_section_id::RELR_DYN),
|inputs| {
inputs.has_data_in_section(output_section_id::RELR_DYN)
&& !has_android_relr_tags(inputs)
},
|inputs| inputs.size_of_section(output_section_id::RELR_DYN),
),
DynamicEntryWriter::optional(
object::elf::DT_RELRENT,
|inputs| inputs.has_data_in_section(output_section_id::RELR_DYN),
|inputs| {
inputs.has_data_in_section(output_section_id::RELR_DYN)
&& !has_android_relr_tags(inputs)
},
|_| elf::RELR_ENTRY_SIZE,
),
DynamicEntryWriter::optional(
// TODO(object): Not yet added
0x6fff_e000,
|inputs| {
inputs.has_data_in_section(output_section_id::RELR_DYN) && has_android_relr_tags(inputs)
},
|inputs| inputs.vma_of_section(output_section_id::RELR_DYN),
),
DynamicEntryWriter::optional(
// TODO(object): Not yet added
0x6fff_e001,
|inputs| {
inputs.has_data_in_section(output_section_id::RELR_DYN) && has_android_relr_tags(inputs)
},
|inputs| inputs.size_of_section(output_section_id::RELR_DYN),
),
DynamicEntryWriter::optional(
// TODO(object): Not yet added
0x6fff_e003,
|inputs| {
inputs.has_data_in_section(output_section_id::RELR_DYN) && has_android_relr_tags(inputs)
},
|_| elf::RELR_ENTRY_SIZE,
),
DynamicEntryWriter::optional(
Expand Down Expand Up @@ -4849,7 +4882,14 @@ fn write_section_headers(out: &mut [u8], layout: &ElfLayout) -> Result {
let entry = entries.next().unwrap();
let e = LittleEndian;
entry.sh_name.set(e, name_offset);
entry.sh_type.set(e, section_type.raw());

let sh_type = if layout.args().use_android_relr_tags && section_type == sht::RELR {
// TODO(object): Not yet added
0x6fffff00
} else {
section_type.raw()
};
entry.sh_type.set(e, sh_type);

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

fn has_android_relr_tags(inputs: &DynamicEntryInputs) -> bool {
inputs.args.use_android_relr_tags
}

pub(crate) fn verify_resolution_allocation(
output_sections: &OutputSections<Elf>,
output_order: &OutputOrder,
Expand Down
Loading