mirror of
https://github.com/rui314/mold.git
synced 2026-11-07 09:16:04 -10:00
Build a -r output's LC_LINKER_OPTION commands with the other load commands
relocatable.rs built its LC_LINKER_OPTION commands itself (linker_option_command). The load commands are chunks/mod.rs's create_*_cmd builders, which -r already takes LC_BUILD_VERSION's from; this one is create_linker_option_cmd there now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
720b2c5776
commit
50074775e4
2 files changed
+18
-18
No files matched your search
@@ -695,6 +695,23 @@ fn create_string_cmd(kind: u32, path: &[u8]) -> Vec<u8> {
|
||||
append_string(to_vec(&cmd), path)
|
||||
}
|
||||
|
||||
/// An LC_LINKER_OPTION command, which a -r output carries: cmd,
|
||||
/// cmdsize, count, then the NUL-terminated strings, padded to 8 bytes.
|
||||
pub fn create_linker_option_cmd(opt: &[Vec<u8>]) -> Vec<u8> {
|
||||
let mut cmd = Vec::new();
|
||||
cmd.extend_from_slice(&LC_LINKER_OPTION.to_le_bytes());
|
||||
cmd.extend_from_slice(&0u32.to_le_bytes());
|
||||
cmd.extend_from_slice(&(opt.len() as u32).to_le_bytes());
|
||||
for s in opt {
|
||||
cmd.extend_from_slice(s);
|
||||
cmd.push(0);
|
||||
}
|
||||
cmd.resize(crate::util::align_to(cmd.len() as u64, 8) as usize, 0);
|
||||
let cmdsize = cmd.len() as u32;
|
||||
cmd[4..8].copy_from_slice(&cmdsize.to_le_bytes());
|
||||
cmd
|
||||
}
|
||||
|
||||
/// The address of the entry point symbol, or 0 for an image without
|
||||
/// one, or for one that is undefined (see passes::check_entry_point).
|
||||
fn entry_addr<E: Target>(ctx: &Context<E>) -> u64 {
|
||||
|
||||
+1
-18
@@ -352,7 +352,7 @@ impl LoadCommands {
|
||||
version,
|
||||
linker_options: relocatable_linker_options(ctx)
|
||||
.iter()
|
||||
.map(|opt| linker_option_command(opt))
|
||||
.map(|opt| crate::chunks::create_linker_option_cmd(opt))
|
||||
.collect(),
|
||||
dice: crate::chunks::data_in_code::construct(ctx, |hdr| hdr.addr),
|
||||
loh: optimization_hints(ctx),
|
||||
@@ -376,23 +376,6 @@ impl LoadCommands {
|
||||
}
|
||||
}
|
||||
|
||||
/// An LC_LINKER_OPTION command: cmd, cmdsize, count, then the
|
||||
/// NUL-terminated strings, padded to 8 bytes.
|
||||
fn linker_option_command(opt: &[Vec<u8>]) -> Vec<u8> {
|
||||
let mut cmd = Vec::new();
|
||||
cmd.extend_from_slice(&LC_LINKER_OPTION.to_le_bytes());
|
||||
cmd.extend_from_slice(&0u32.to_le_bytes());
|
||||
cmd.extend_from_slice(&(opt.len() as u32).to_le_bytes());
|
||||
for s in opt {
|
||||
cmd.extend_from_slice(s);
|
||||
cmd.push(0);
|
||||
}
|
||||
cmd.resize(align_to(cmd.len() as u64, 8) as usize, 0);
|
||||
let cmdsize = cmd.len() as u32;
|
||||
cmd[4..8].copy_from_slice(&cmdsize.to_le_bytes());
|
||||
cmd
|
||||
}
|
||||
|
||||
/// Places the sections' contents in the file past the load commands,
|
||||
/// which end at `cmds_end`, each aligned as in the address space, and
|
||||
/// returns where they start and end. A zero-fill section takes no file
|
||||
|
||||
Reference in new issue
Block a user