[PATCH] D41735: Use uint64_t to store the ELF sh_entsize field.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 5 08:13:04 PST 2018


Do you have a need for such a large entsize? If not I would suggest
producing an error saying that we don't support it.

Thanks,
Rafael


Matt Davis via Phabricator via llvm-commits
<llvm-commits at lists.llvm.org> writes:

> mattd created this revision.
> mattd added reviewers: rengolin, grosbach.
> Herald added a subscriber: emaste.
>
> Use 64bit sizes for sh_entsize.
>
> Elf64_Shdr uses 64bit sizes (Elf64_Xword) to represent the section entry size
> (sh_entsize).  The internal LLVM representation maintains this field as a 32bit
> value, regardless if Elf32 or Elf64. This change ensures that enormous
> entsizes (values larger than 2^32) can be represented internally.
>
>
> https://reviews.llvm.org/D41735
>
> Files:
>   include/llvm/MC/MCContext.h
>   include/llvm/MC/MCSectionELF.h
>   lib/MC/MCContext.cpp
>   test/MC/ELF/entsize.s
>
> Index: test/MC/ELF/entsize.s
> ===================================================================
> --- test/MC/ELF/entsize.s
> +++ test/MC/ELF/entsize.s
> @@ -32,6 +32,9 @@
>      .quad 42
>      .quad 42
>  
> + // Large sh_entsize
> +	.section ".enormous_sh_entsize","M", at progbits,0x100000000
> +
>  // CHECK:        Section {
>  // CHECK:          Index:
>  // CHECK:          Name: .rodata.str1.1
> @@ -82,3 +85,18 @@
>  // CHECK-NEXT:     AddressAlignment: 1
>  // CHECK-NEXT:     EntrySize: 8
>  // CHECK-NEXT:   }
> +// CHECK:        Section {
> +// CHECK:          Index:
> +// CHECK:          Name: .enormous_sh_entsize
> +// CHECK-NEXT:     Type: SHT_PROGBITS
> +// CHECK-NEXT:     Flags [
> +// CHECK-NEXT:       SHF_MERGE
> +// CHECK-NEXT:     ]
> +// CHECK-NEXT:     Address:
> +// CHECK-NEXT:     Offset:
> +// CHECK-NEXT:     Size:
> +// CHECK-NEXT:     Link:
> +// CHECK-NEXT:     Info:
> +// CHECK-NEXT:     AddressAlignment:
> +// CHECK-NEXT:     EntrySize: 4294967296
> +// CHECK-NEXT:   }
> Index: lib/MC/MCContext.cpp
> ===================================================================
> --- lib/MC/MCContext.cpp
> +++ lib/MC/MCContext.cpp
> @@ -314,7 +314,7 @@
>  
>  MCSectionELF *MCContext::createELFSectionImpl(StringRef Section, unsigned Type,
>                                                unsigned Flags, SectionKind K,
> -                                              unsigned EntrySize,
> +                                              uint64_t EntrySize,
>                                                const MCSymbolELF *Group,
>                                                unsigned UniqueID,
>                                                const MCSymbolELF *Associated) {
> @@ -348,7 +348,7 @@
>  }
>  
>  MCSectionELF *MCContext::createELFRelSection(const Twine &Name, unsigned Type,
> -                                             unsigned Flags, unsigned EntrySize,
> +                                             unsigned Flags, uint64_t EntrySize,
>                                               const MCSymbolELF *Group,
>                                               const MCSectionELF *RelInfoSection) {
>    StringMap<bool>::iterator I;
> @@ -364,12 +364,12 @@
>  MCSectionELF *MCContext::getELFNamedSection(const Twine &Prefix,
>                                              const Twine &Suffix, unsigned Type,
>                                              unsigned Flags,
> -                                            unsigned EntrySize) {
> +                                            uint64_t EntrySize) {
>    return getELFSection(Prefix + "." + Suffix, Type, Flags, EntrySize, Suffix);
>  }
>  
>  MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
> -                                       unsigned Flags, unsigned EntrySize,
> +                                       unsigned Flags, uint64_t EntrySize,
>                                         const Twine &Group, unsigned UniqueID,
>                                         const MCSymbolELF *Associated) {
>    MCSymbolELF *GroupSym = nullptr;
> @@ -381,7 +381,7 @@
>  }
>  
>  MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type,
> -                                       unsigned Flags, unsigned EntrySize,
> +                                       unsigned Flags, uint64_t EntrySize,
>                                         const MCSymbolELF *GroupSym,
>                                         unsigned UniqueID,
>                                         const MCSymbolELF *Associated) {
> Index: include/llvm/MC/MCSectionELF.h
> ===================================================================
> --- include/llvm/MC/MCSectionELF.h
> +++ include/llvm/MC/MCSectionELF.h
> @@ -18,6 +18,7 @@
>  #include "llvm/MC/MCSection.h"
>  #include "llvm/MC/MCSymbolELF.h"
>  #include "llvm/MC/SectionKind.h"
> +#include <cstdint>
>  
>  namespace llvm {
>  
> @@ -38,10 +39,10 @@
>  
>    unsigned UniqueID;
>  
> -  /// The size of each entry in this section. This size only makes sense for
> +  /// This is the sh_entsize field of a section. This size only makes sense for
>    /// sections that contain fixed-sized entries. If a section does not contain
>    /// fixed-sized entries 'EntrySize' will be 0.
> -  unsigned EntrySize;
> +  uint64_t EntrySize;
>  
>    const MCSymbolELF *Group;
>  
> @@ -52,7 +53,7 @@
>    friend class MCContext;
>  
>    MCSectionELF(StringRef Section, unsigned type, unsigned flags, SectionKind K,
> -               unsigned entrySize, const MCSymbolELF *group, unsigned UniqueID,
> +               uint64_t entrySize, const MCSymbolELF *group, unsigned UniqueID,
>                 MCSymbol *Begin, const MCSymbolELF *AssociatedSymbol)
>        : MCSection(SV_ELF, K, Begin), SectionName(Section), Type(type),
>          Flags(flags), UniqueID(UniqueID), EntrySize(entrySize), Group(group),
> @@ -73,7 +74,7 @@
>    StringRef getSectionName() const { return SectionName; }
>    unsigned getType() const { return Type; }
>    unsigned getFlags() const { return Flags; }
> -  unsigned getEntrySize() const { return EntrySize; }
> +  uint64_t getEntrySize() const { return EntrySize; }
>    void setFlags(unsigned F) { Flags = F; }
>    const MCSymbolELF *getGroup() const { return Group; }
>  
> Index: include/llvm/MC/MCContext.h
> ===================================================================
> --- include/llvm/MC/MCContext.h
> +++ include/llvm/MC/MCContext.h
> @@ -263,7 +263,7 @@
>  
>      MCSectionELF *createELFSectionImpl(StringRef Section, unsigned Type,
>                                         unsigned Flags, SectionKind K,
> -                                       unsigned EntrySize,
> +                                       uint64_t EntrySize,
>                                         const MCSymbolELF *Group,
>                                         unsigned UniqueID,
>                                         const MCSymbolELF *Associated);
> @@ -382,13 +382,13 @@
>      }
>  
>      MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
> -                                unsigned Flags, unsigned EntrySize,
> +                                unsigned Flags, uint64_t EntrySize,
>                                  const Twine &Group) {
>        return getELFSection(Section, Type, Flags, EntrySize, Group, ~0);
>      }
>  
>      MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
> -                                unsigned Flags, unsigned EntrySize,
> +                                unsigned Flags, uint64_t EntrySize,
>                                  const Twine &Group, unsigned UniqueID) {
>        return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID,
>                             nullptr);
> @@ -395,12 +395,12 @@
>      }
>  
>      MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
> -                                unsigned Flags, unsigned EntrySize,
> +                                unsigned Flags, uint64_t EntrySize,
>                                  const Twine &Group, unsigned UniqueID,
>                                  const MCSymbolELF *Associated);
>  
>      MCSectionELF *getELFSection(const Twine &Section, unsigned Type,
> -                                unsigned Flags, unsigned EntrySize,
> +                                unsigned Flags, uint64_t EntrySize,
>                                  const MCSymbolELF *Group, unsigned UniqueID,
>                                  const MCSymbolELF *Associated);
>  
> @@ -410,10 +410,10 @@
>      /// configure this named section.
>      MCSectionELF *getELFNamedSection(const Twine &Prefix, const Twine &Suffix,
>                                       unsigned Type, unsigned Flags,
> -                                     unsigned EntrySize = 0);
> +                                     uint64_t EntrySize = 0);
>  
>      MCSectionELF *createELFRelSection(const Twine &Name, unsigned Type,
> -                                      unsigned Flags, unsigned EntrySize,
> +                                      unsigned Flags, uint64_t EntrySize,
>                                        const MCSymbolELF *Group,
>                                        const MCSectionELF *RelInfoSection);
>  
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list