This is an archive of the discontinued LLVM Phabricator instance.

[MCObjectFileInfo] Add getPCSection() helper
AbandonedPublic

Authored by melver on Aug 1 2022, 1:55 AM.

Details

Reviewers
dvyukov
MaskRay
Summary

Add MCObjectFileInfo::getPCSection() helper to get a section for PCs
requested via MD_pcsections.

Diff Detail

Event Timeline

melver created this revision.Aug 1 2022, 1:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 1:55 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
melver requested review of this revision.Aug 1 2022, 1:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 1:55 AM
dvyukov added inline comments.Aug 2 2022, 1:05 AM
llvm/lib/MC/MCObjectFileInfo.cpp
1189

Do we actually plan to write to these sections? Does setting SHF_WRITE prevent sharing of pages across multiple processes? Of SHF_WRITE pages still mapped as shared/write-protected first and then subject to copy-on-write?

melver added a subscriber: MaskRay.Aug 2 2022, 7:28 AM
melver added inline comments.
llvm/lib/MC/MCObjectFileInfo.cpp
1189

This was needed for relocations (because linker needs section writable if it contains relocations).
glibc seems to map sections as MAP_COPY (AFAIK), which is MAP_PRIVATE on Linux, so it'll COW.

Now that we have relative relocations, maybe we don't need it anymore, but I'd like to reserve the option to modify the data in-place (whether we do it, or someone else finds a use for it).
Changing it again in future is too painful, and we're likely stuck with whatever we decide now. I don't see a huge downside to it being writable (there's no security concern here).

Cc @MaskRay

dvyukov added inline comments.Aug 2 2022, 7:34 AM
llvm/lib/MC/MCObjectFileInfo.cpp
1189

If it's shared across processes and COW, then it should be fine.

MaskRay added inline comments.Aug 3 2022, 3:10 PM
llvm/lib/MC/MCObjectFileInfo.cpp
1189

Note: Relocate relocations usually refer to R_*_RELATIVE. PC-relative static relocations are very different and should not be conflated.

melver abandoned this revision.Aug 4 2022, 10:00 AM

Squashed into "[AsmPrinter] Emit PCs into requested PCSections".

melver edited the summary of this revision. (Show Details)Aug 4 2022, 10:02 AM