Skip to content

Commit

Permalink
Add N_NO_DEAD_STRIP flag to section symbols to ensure that data at th…
Browse files Browse the repository at this point in the history
…e 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.
  • Loading branch information
filipnavara authored Aug 19, 2024
1 parent dec4568 commit 0c90519
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private protected override void EmitSectionsAndLayout()
Name = $"lsection{sectionIndex}",
Section = section,
Value = section.VirtualAddress,
Descriptor = 0,
Descriptor = N_NO_DEAD_STRIP,
Type = N_SECT,
};
_symbolTable.Add(machSymbol);
Expand Down

0 comments on commit 0c90519

Please sign in to comment.