Skip to content

Commit f856f4f

Browse files
authored
[ObjWriter/Mach-O] Mark non-global symbols as .private_extern to match 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.
1 parent 0c90519 commit f856f4f

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/MachNative.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ internal static class MachNative
9696
public const byte N_INDR = 0xA;
9797
public const byte N_SECT = 0xE;
9898
public const byte N_PBUD = 0xC;
99+
public const byte N_PEXT = 0x10;
99100

100101
// Symbol descriptor flags
101102
public const ushort REFERENCE_FLAG_UNDEFINED_NON_LAZY = 0;

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/MachObjectWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ private protected override void EmitSymbolTable(
484484
Section = section,
485485
Value = section.VirtualAddress + (ulong)definition.Value,
486486
Descriptor = N_NO_DEAD_STRIP,
487-
Type = N_SECT | N_EXT,
487+
Type = (byte)(N_SECT | N_EXT | (definition.Global ? 0 : N_PEXT)),
488488
});
489489
}
490490
sortedDefinedSymbols.Sort((symA, symB) => string.CompareOrdinal(symA.Name, symB.Name));

0 commit comments

Comments
 (0)