Skip to content

Instantly share code, notes, and snippets.

@jedisct1
Last active September 4, 2019 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedisct1/4eccc9f79d8db408e1c1717a4d446d49 to your computer and use it in GitHub Desktop.
Save jedisct1/4eccc9f79d8db408e1c1717a4d446d49 to your computer and use it in GitHub Desktop.
diff --git a/src/write/macho.rs b/src/write/macho.rs
index dbbe5df..48f7b6b 100644
--- a/src/write/macho.rs
+++ b/src/write/macho.rs
@@ -137,6 +137,17 @@ impl Object {
let mut strtab = StringTable::default();
let mut symbol_offsets = vec![SymbolOffsets::default(); self.symbols.len()];
let mut nsyms = 0;
+
+ let prefixed_symbols: Vec<_> = self
+ .symbols
+ .iter()
+ .map(|symbol| {
+ let mut prefixed = Vec::with_capacity(1 + symbol.name.len());
+ prefixed.push(0x5f);
+ prefixed.extend_from_slice(&symbol.name);
+ prefixed
+ })
+ .collect();
for (index, symbol) in self.symbols.iter().enumerate() {
if !symbol.is_undefined() {
match symbol.kind {
@@ -148,7 +159,11 @@ impl Object {
symbol_offsets[index].index = nsyms;
nsyms += 1;
if !symbol.name.is_empty() {
- symbol_offsets[index].str_id = Some(strtab.add(&symbol.name));
+ symbol_offsets[index].str_id = if symbol.is_local() {
+ Some(strtab.add(&symbol.name))
+ } else {
+ Some(strtab.add(&prefixed_symbols[index]))
+ };
}
}
@@ -406,6 +421,9 @@ impl Object {
(RelocationKind::Relative, RelocationEncoding::X86Branch, -4) => {
(1, mach::X86_64_RELOC_BRANCH)
}
+ (RelocationKind::Relative, RelocationEncoding::Generic, -4) => {
+ (1, mach::X86_64_RELOC_SIGNED)
+ }
(RelocationKind::PltRelative, RelocationEncoding::X86Branch, -4) => {
(1, mach::X86_64_RELOC_BRANCH)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment