-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ELF] Support relocatable files using CREL with explicit addends #98115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7f7f5d7
09f81a9
39d9244
b9f8a55
da5c41c
ba18dfb
091b641
f8ad6e9
c458b20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,17 +35,21 @@ class OutputSection; | |
|
||
LLVM_LIBRARY_VISIBILITY extern std::vector<Partition> partitions; | ||
|
||
// Returned by InputSectionBase::relsOrRelas. At least one member is empty. | ||
// Returned by InputSectionBase::relsOrRelas. At most one member is empty. | ||
template <class ELFT> struct RelsOrRelas { | ||
Relocs<typename ELFT::Rel> rels; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the comment above now stale? I'd expect only one member to be non-empty now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the comment has been stale before this patch. Updated |
||
Relocs<typename ELFT::Rela> relas; | ||
Relocs<typename ELFT::Crel> crels; | ||
bool areRelocsRel() const { return rels.size(); } | ||
bool areRelocsCrel() const { return crels.size(); } | ||
}; | ||
|
||
#define invokeOnRelocs(sec, f, ...) \ | ||
{ \ | ||
const RelsOrRelas<ELFT> rs = (sec).template relsOrRelas<ELFT>(); \ | ||
if (rs.areRelocsRel()) \ | ||
if (rs.areRelocsCrel()) \ | ||
f(__VA_ARGS__, rs.crels); \ | ||
else if (rs.areRelocsRel()) \ | ||
f(__VA_ARGS__, rs.rels); \ | ||
else \ | ||
f(__VA_ARGS__, rs.relas); \ | ||
|
@@ -209,7 +213,8 @@ class InputSectionBase : public SectionBase { | |
// used by --gc-sections. | ||
InputSectionBase *nextInSectionGroup = nullptr; | ||
|
||
template <class ELFT> RelsOrRelas<ELFT> relsOrRelas() const; | ||
template <class ELFT> | ||
RelsOrRelas<ELFT> relsOrRelas(bool supportsCrel = true) const; | ||
|
||
// InputSections that are dependent on us (reverse dependency for GC) | ||
llvm::TinyPtrVector<InputSection *> dependentSections; | ||
|
@@ -483,7 +488,8 @@ class SyntheticSection : public InputSection { | |
}; | ||
|
||
inline bool isStaticRelSecType(uint32_t type) { | ||
return type == llvm::ELF::SHT_RELA || type == llvm::ELF::SHT_REL; | ||
return type == llvm::ELF::SHT_RELA || type == llvm::ELF::SHT_CREL || | ||
type == llvm::ELF::SHT_REL; | ||
} | ||
|
||
inline bool isDebugSection(const InputSectionBase &sec) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,13 @@ static uint64_t getAddend(InputSectionBase &sec, | |
return rel.r_addend; | ||
} | ||
|
||
// Currently, we assume all input CREL relocations have an explicit addend. | ||
template <class ELFT> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a comment that we assume all input Crel relocations will have an explicit addend? |
||
static uint64_t getAddend(InputSectionBase &sec, | ||
const typename ELFT::Crel &rel) { | ||
return rel.r_addend; | ||
} | ||
|
||
template <class ELFT> | ||
template <class RelTy> | ||
void MarkLive<ELFT>::resolveReloc(InputSectionBase &sec, RelTy &rel, | ||
|
@@ -239,7 +246,8 @@ template <class ELFT> void MarkLive<ELFT>::run() { | |
// all of them. We also want to preserve personality routines and LSDA | ||
// referenced by .eh_frame sections, so we scan them for that here. | ||
for (EhInputSection *eh : ctx.ehInputSections) { | ||
const RelsOrRelas<ELFT> rels = eh->template relsOrRelas<ELFT>(); | ||
const RelsOrRelas<ELFT> rels = | ||
eh->template relsOrRelas<ELFT>(/*supportsCrel=*/false); | ||
if (rels.areRelocsRel()) | ||
scanEhFrameSection(*eh, rels.rels); | ||
else if (rels.relas.size()) | ||
|
@@ -310,6 +318,8 @@ template <class ELFT> void MarkLive<ELFT>::mark() { | |
resolveReloc(sec, rel, false); | ||
for (const typename ELFT::Rela &rel : rels.relas) | ||
resolveReloc(sec, rel, false); | ||
for (const typename ELFT::Crel &rel : rels.crels) | ||
resolveReloc(sec, rel, false); | ||
|
||
for (InputSectionBase *isec : sec.dependentSections) | ||
enqueue(isec, 0); | ||
|
Uh oh!
There was an error while loading. Please reload this page.