This is an archive of the discontinued LLVM Phabricator instance.

[lld-macho] Add isCodeSection()
ClosedPublic

Authored by int3 on Dec 1 2020, 2:08 PM.

Details

Reviewers
clayborg
Group Reviewers
Restricted Project
Commits
rGc7dbaec396ef: [lld-macho] Add isCodeSection()
Summary

This is the same logic that ld64 uses to determine which sections
contain functions. This was added so that we could determine which
STABS entries should be N_FUN.

Diff Detail

Event Timeline

int3 created this revision.Dec 1 2020, 2:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2020, 2:08 PM
int3 requested review of this revision.Dec 1 2020, 2:08 PM
clayborg accepted this revision.Dec 1 2020, 2:36 PM
clayborg added inline comments.
lld/MachO/InputSection.cpp
67

BTW there is also a S_ATTR_SOME_INSTRUCTIONS attribute we might be able to use and improve.

This revision is now accepted and ready to land.Dec 1 2020, 2:36 PM
int3 added inline comments.Dec 1 2020, 2:41 PM
lld/MachO/InputSection.cpp
67

hmm I don't think ld64 uses S_ATTR_SOME_INSTRUCTIONS to identify code sections. (Though it does ensure that every code section it emits has both S_ATTR_SOME_INSTRUCTIONS and S_ATTR_PURE_INSTRUCTIONS set.)

smeenai added a subscriber: smeenai.Dec 1 2020, 2:48 PM
smeenai added inline comments.
lld/MachO/InputSection.cpp
67

Out of curiosity, how does S_ATTR_PURE_INSTRUCTIONS interact with LC_DATA_IN_CODE? For example, if Clang ends up emitting an ARM constant pool into the text section (so it's not technically pure instructions), is the section still marked as pure instructions?

smeenai added inline comments.Dec 1 2020, 2:54 PM
lld/MachO/InputSection.cpp
67

To answer my own question, I'm having a hard time getting clang to produce a constant pool for arm64, but at least for armv7, it marks __TEXT,__text as pure instructions despite the constant pool: https://godbolt.org/z/MaT9E1

int3 added inline comments.Dec 1 2020, 2:58 PM
lld/MachO/InputSection.cpp
67

thanks for checking that case :)

This revision was landed with ongoing or failed builds.Dec 1 2020, 3:05 PM
This revision was automatically updated to reflect the committed changes.