llvm.org GIT mirror llvm / 3a129c8
This patch adds new functions to the SectionRef and ObjectFile interfaces to determine whether or not a section is meant to be read-only. These functions will be used by the MCJIT RuntimeDyld to give hints to the memory manager during the object loading process in a future patch. Patch by Ashok Thirumurthi. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165586 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Kaylor 8 years ago
6 changed file(s) with 41 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
127127 virtual error_code isSectionBSS(DataRefImpl Sec, bool &Res) const;
128128 virtual error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const;
129129 virtual error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const;
130 virtual error_code isSectionReadOnlyData(DataRefImpl Sec, bool &Res) const;
130131 virtual error_code isSectionRequiredForExecution(DataRefImpl Sec,
131132 bool &Res) const;
132133 virtual error_code sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb,
639639 bool &Res) const;
640640 virtual error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const;
641641 virtual error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const;
642 virtual error_code isSectionReadOnlyData(DataRefImpl Sec, bool &Res) const;
642643 virtual error_code sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb,
643644 bool &Result) const;
644645 virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const;
12871288 }
12881289
12891290 template
1290 error_code ELFObjectFile::isSectionZeroInit(DataRefImpl Sec,
1291 error_code ELFObjectFile
1292 ::isSectionZeroInit(DataRefImpl Sec,
12911293 bool &Result) const {
12921294 const Elf_Shdr *sec = reinterpret_cast(Sec.p);
12931295 // For ELF, all zero-init sections are virtual (that is, they occupy no space
12961298 Result = true;
12971299 else
12981300 Result = false;
1301 return object_error::success;
1302 }
1303
1304 template
1305 error_code ELFObjectFile
1306 ::isSectionReadOnlyData(DataRefImpl Sec,
1307 bool &Result) const {
1308 const Elf_Shdr *sec = reinterpret_cast(Sec.p);
1309 if (sec->sh_flags & ELF::SHF_WRITE || sec->sh_flags & ELF::SHF_EXECINSTR)
1310 Result = false;
1311 else
1312 Result = true;
12991313 return object_error::success;
13001314 }
13011315
7575 bool &Res) const;
7676 virtual error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const;
7777 virtual error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const;
78 virtual error_code isSectionReadOnlyData(DataRefImpl Sec, bool &Res) const;
7879 virtual error_code sectionContainsSymbol(DataRefImpl DRI, DataRefImpl S,
7980 bool &Result) const;
8081 virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const;
162162 error_code isRequiredForExecution(bool &Result) const;
163163 error_code isVirtual(bool &Result) const;
164164 error_code isZeroInit(bool &Result) const;
165 error_code isReadOnlyData(bool &Result) const;
165166
166167 error_code containsSymbol(SymbolRef S, bool &Result) const;
167168
315316 // A section is 'virtual' if its contents aren't present in the object image.
316317 virtual error_code isSectionVirtual(DataRefImpl Sec, bool &Res) const = 0;
317318 virtual error_code isSectionZeroInit(DataRefImpl Sec, bool &Res) const = 0;
319 virtual error_code isSectionReadOnlyData(DataRefImpl Sec, bool &Res) const = 0;
318320 virtual error_code sectionContainsSymbol(DataRefImpl Sec, DataRefImpl Symb,
319321 bool &Result) const = 0;
320322 virtual relocation_iterator getSectionRelBegin(DataRefImpl Sec) const = 0;
509511 return OwningObject->isSectionZeroInit(SectionPimpl, Result);
510512 }
511513
514 inline error_code SectionRef::isReadOnlyData(bool &Result) const {
515 return OwningObject->isSectionReadOnlyData(SectionPimpl, Result);
516 }
517
512518 inline error_code SectionRef::containsSymbol(SymbolRef S, bool &Result) const {
513519 return OwningObject->sectionContainsSymbol(SectionPimpl, S.SymbolPimpl,
514520 Result);
372372 error_code COFFObjectFile::isSectionZeroInit(DataRefImpl Sec,
373373 bool &Result) const {
374374 // FIXME: Unimplemented
375 Result = false;
376 return object_error::success;
377 }
378
379 error_code COFFObjectFile::isSectionReadOnlyData(DataRefImpl Sec,
380 bool &Result) const {
381 // FIXME: Unimplemented.
375382 Result = false;
376383 return object_error::success;
377384 }
608608 SectionType == MachO::SectionTypeZeroFillLarge);
609609 }
610610
611 return object_error::success;
612 }
613
614 error_code MachOObjectFile::isSectionReadOnlyData(DataRefImpl Sec,
615 bool &Result) const {
616 // Consider using the code from isSectionText to look for __const sections.
617 // Alternately, emit S_ATTR_PURE_INSTRUCTIONS and/or S_ATTR_SOME_INSTRUCTIONS
618 // to use section attributes to distinguish code from data.
619
620 // FIXME: Unimplemented.
621 Result = false;
611622 return object_error::success;
612623 }
613624