This is an archive of the discontinued LLVM Phabricator instance.

[Object] Add IsSectionReadOnly section interface
AbandonedPublic

Authored by Amir on May 11 2021, 4:21 PM.

Details

Summary

The interface is implemented for ELF and checks if ALLOC and PROGBITS attributes
are set and WRITE is not set. Not implemented for the rest of formats.

Diff Detail

Event Timeline

Amir created this revision.May 11 2021, 4:21 PM
Amir requested review of this revision.May 11 2021, 4:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2021, 4:21 PM

What's the motivation for this? Why did you decide that anything other than SHF_WRITE has implication on whether a section is read-only or not?

What's the motivation for this?

+1

This needs test anyway.

Hi folks, this patch is part of an effort to bring BOLT to the LLVM repo, so the use case comes from BOLT.

The main use case for this is here:
https://github.com/facebookincubator/BOLT/blob/rebased/bolt/src/Passes/BinaryPasses.cpp#L1100

This is a pass that checks for a memory load instruction that is accessing a read-only section, and converts it into "load immediate" to save a data memory access.

MaskRay requested changes to this revision.May 12 2021, 12:20 PM

Most binary formats have a concept of writable, but not a concept of readonly.
In ELF, you refine readonly to mean something SHF_ALLOC & SHT_PROGBITS which is probably really BOLT specific.
Having the interface in lib/Object will just cause confusion to lib/Object users.

This revision now requires changes to proceed.May 12 2021, 12:20 PM
Amir abandoned this revision.May 12 2021, 11:14 PM

Thank you for the comments. Indeed this "read-only" is not well-defined. What we actually want to test is if the section is writable or not. Abandoning this diff.