Skip to content

Commit

Permalink
[ObjWriter/Mach-O] Mark non-global symbols as .private_extern to matc…
Browse files Browse the repository at this point in the history
…h ELF (#106446)

Extracted from #106224

`.private_extern` is the logical equivalent of `.hidden`+`.global` in ELF. We already emit those flags in ELF, so do it in Mach-O too.

Documentation for `.private_extern`:
> It's used to mark symbols with limited visibility. When the file is fed to the static linker, it clears the N_EXT bit for each symbol with the N_PEXT bit set. The ld option -keep_private_externs turns off this behavior.
  • Loading branch information
filipnavara authored Aug 19, 2024
1 parent 0c90519 commit f856f4f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ internal static class MachNative
public const byte N_INDR = 0xA;
public const byte N_SECT = 0xE;
public const byte N_PBUD = 0xC;
public const byte N_PEXT = 0x10;

// Symbol descriptor flags
public const ushort REFERENCE_FLAG_UNDEFINED_NON_LAZY = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ private protected override void EmitSymbolTable(
Section = section,
Value = section.VirtualAddress + (ulong)definition.Value,
Descriptor = N_NO_DEAD_STRIP,
Type = N_SECT | N_EXT,
Type = (byte)(N_SECT | N_EXT | (definition.Global ? 0 : N_PEXT)),
});
}
sortedDefinedSymbols.Sort((symA, symB) => string.CompareOrdinal(symA.Name, symB.Name));
Expand Down

0 comments on commit f856f4f

Please sign in to comment.