[lld] 72bedf4 - [ELF] Inline InputSection::getParent. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 8 11:26:16 PST 2022


Author: Fangrui Song
Date: 2022-03-08T11:26:12-08:00
New Revision: 72bedf46c760ad7670801456450b57f360652be3

URL: https://github.com/llvm/llvm-project/commit/72bedf46c760ad7670801456450b57f360652be3
DIFF: https://github.com/llvm/llvm-project/commit/72bedf46c760ad7670801456450b57f360652be3.diff

LOG: [ELF] Inline InputSection::getParent. NFC

Combined with the previous change, lld executable is ~2K smaller and some code
paths using InputSection::getParent are more efficient.

The fragmented headers lead to a design limitation that OutputSection has to be
incomplete, so we cannot use static_cast.

Added: 
    

Modified: 
    lld/ELF/InputSection.cpp
    lld/ELF/InputSection.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 497d97af2f42b..1d23c065000cb 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -323,10 +323,6 @@ InputSection::InputSection(ObjFile<ELFT> &f, const typename ELFT::Shdr &header,
                            StringRef name)
     : InputSectionBase(f, header, name, InputSectionBase::Regular) {}
 
-OutputSection *InputSection::getParent() const {
-  return cast_or_null<OutputSection>(parent);
-}
-
 // Copy SHT_GROUP section contents. Used only for the -r option.
 template <class ELFT> void InputSection::copyShtGroup(uint8_t *buf) {
   // ELFT::Word is the 32-bit integral type in the target endianness.

diff  --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index 4907e10fcbfc5..7e23e565b3d34 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -348,7 +348,9 @@ class InputSection : public InputSectionBase {
   // beginning of the output section.
   template <class ELFT> void writeTo(uint8_t *buf);
 
-  OutputSection *getParent() const;
+  OutputSection *getParent() const {
+    return reinterpret_cast<OutputSection *>(parent);
+  }
 
   // This variable has two usages. Initially, it represents an index in the
   // OutputSection's InputSection list, and is used when ordering SHF_LINK_ORDER


        


More information about the llvm-commits mailing list