Skip to content

Commit 0c90519

Browse files
authored
Add N_NO_DEAD_STRIP flag to section symbols to ensure that data at the beginning of the section are not stripped if there's no other N_NO_DEAD_STRIP symbol referencing them (#106444)
Extracted from #106224. PR #103039 added `N_NO_DEAD_STRIP` flag to all symbols emitted by ILC and enabled the dead code stripping in the native linker. It failed to handle one specific edge case that is luckily not happening in the wild. If the first node emitted into a section has a symbol with non-zero offset NN the first `N_NO_DEAD_STRIP` symbol is not pointing at the start of the section. The native linker then splits up the section into atom and the first atom from offset 0 to offset NN is never referenced and becomes eligible for dead code stripping. Since we emit a symbol for each section start (for use in section-relative relocations) we can just mark the symbol with `N_NO_DEAD_STRIP` to resolve the issue.
1 parent dec4568 commit 0c90519

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private protected override void EmitSectionsAndLayout()
113113
Name = $"lsection{sectionIndex}",
114114
Section = section,
115115
Value = section.VirtualAddress,
116-
Descriptor = 0,
116+
Descriptor = N_NO_DEAD_STRIP,
117117
Type = N_SECT,
118118
};
119119
_symbolTable.Add(machSymbol);

0 commit comments

Comments
 (0)