Commit 7a587ca9 authored by Georgii Rymar's avatar Georgii Rymar
Browse files

[yaml2obj] - Rename FileHeader::SH* fields.

In D83482 we agreed to name e_* fields that are used for overriding
values (like e_phoff) as EPh* (e.g. EPhOff).

Currently we have a set of e_sh* fields that are named inconsistently
with this rule. This patch renames all of them.

Differential revision: https://reviews.llvm.org/D83766
parent c872e809
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -84,11 +84,10 @@ struct FileHeader {
  Optional<llvm::yaml::Hex64> EPhOff;
  Optional<llvm::yaml::Hex16> EPhEntSize;
  Optional<llvm::yaml::Hex16> EPhNum;

  Optional<llvm::yaml::Hex16> SHEntSize;
  Optional<llvm::yaml::Hex64> SHOff;
  Optional<llvm::yaml::Hex16> SHNum;
  Optional<llvm::yaml::Hex16> SHStrNdx;
  Optional<llvm::yaml::Hex16> EShEntSize;
  Optional<llvm::yaml::Hex64> EShOff;
  Optional<llvm::yaml::Hex16> EShNum;
  Optional<llvm::yaml::Hex16> EShStrNdx;
};

struct SectionHeader {
+8 −8
Original line number Diff line number Diff line
@@ -417,21 +417,21 @@ void ELFState<ELFT>::writeELFHeader(raw_ostream &OS, uint64_t SHOff) {
  else
    Header.e_phnum = 0;

  Header.e_shentsize =
      Doc.Header.SHEntSize ? (uint16_t)*Doc.Header.SHEntSize : sizeof(Elf_Shdr);
  Header.e_shentsize = Doc.Header.EShEntSize ? (uint16_t)*Doc.Header.EShEntSize
                                             : sizeof(Elf_Shdr);

  const bool NoShdrs =
      Doc.SectionHeaders && Doc.SectionHeaders->NoHeaders.getValueOr(false);

  if (Doc.Header.SHOff)
    Header.e_shoff = *Doc.Header.SHOff;
  if (Doc.Header.EShOff)
    Header.e_shoff = *Doc.Header.EShOff;
  else if (NoShdrs)
    Header.e_shoff = 0;
  else
    Header.e_shoff = SHOff;

  if (Doc.Header.SHNum)
    Header.e_shnum = *Doc.Header.SHNum;
  if (Doc.Header.EShNum)
    Header.e_shnum = *Doc.Header.EShNum;
  else if (!Doc.SectionHeaders)
    Header.e_shnum = Doc.getSections().size();
  else if (NoShdrs)
@@ -442,8 +442,8 @@ void ELFState<ELFT>::writeELFHeader(raw_ostream &OS, uint64_t SHOff) {
                                      : 0) +
        /*Null section*/ 1;

  if (Doc.Header.SHStrNdx)
    Header.e_shstrndx = *Doc.Header.SHStrNdx;
  if (Doc.Header.EShStrNdx)
    Header.e_shstrndx = *Doc.Header.EShStrNdx;
  else if (NoShdrs || ExcludedSectionHeaders.count(".shstrtab"))
    Header.e_shstrndx = 0;
  else
+4 −5
Original line number Diff line number Diff line
@@ -872,11 +872,10 @@ void MappingTraits<ELFYAML::FileHeader>::mapping(IO &IO,
  IO.mapOptional("EPhOff", FileHdr.EPhOff);
  IO.mapOptional("EPhEntSize", FileHdr.EPhEntSize);
  IO.mapOptional("EPhNum", FileHdr.EPhNum);

  IO.mapOptional("SHEntSize", FileHdr.SHEntSize);
  IO.mapOptional("SHOff", FileHdr.SHOff);
  IO.mapOptional("SHNum", FileHdr.SHNum);
  IO.mapOptional("SHStrNdx", FileHdr.SHStrNdx);
  IO.mapOptional("EShEntSize", FileHdr.EShEntSize);
  IO.mapOptional("EShOff", FileHdr.EShOff);
  IO.mapOptional("EShNum", FileHdr.EShNum);
  IO.mapOptional("EShStrNdx", FileHdr.EShStrNdx);
}

void MappingTraits<ELFYAML::ProgramHeader>::mapping(
+35 −35
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ FileHeader:
  Data:       ELFDATA2LSB
  Type:       ET_REL
  Machine:    EM_X86_64
  SHEntSize: 1
  EShEntSize: 1

## Check that llvm-readobj reports a warning if .symtab has sh_size
## that is not a multiple of sh_entsize.
@@ -310,7 +310,7 @@ FileHeader:
  Data:     ELFDATA2LSB
  Type:     ET_REL
  Machine:  EM_X86_64
  SHNum:   0xFF
  EShNum:   0xFF

## Check llvm-readobj does not crash on a truncated ELF.

@@ -525,7 +525,7 @@ FileHeader:
  Data:      ELFDATA2LSB
  Type:      ET_REL
  Machine:   EM_X86_64
  SHStrNdx: 0xFF
  EShStrNdx: 0xFF
Sections:
  - Name: .foo
    Type: SHT_PROGBITS
@@ -545,7 +545,7 @@ FileHeader:
  Data:     ELFDATA2LSB
  Type:     ET_REL
  Machine:  EM_X86_64
  SHNum:   0x0
  EShNum:   0x0
Sections:
  - Type: SHT_NULL
    Size: 288230376151711743
@@ -564,7 +564,7 @@ FileHeader:
  Data:     ELFDATA2LSB
  Type:     ET_REL
  Machine:  EM_X86_64
  SHNum:   0x0
  EShNum:   0x0
Sections:
  - Type: SHT_NULL
    Size: 288230376151711744
@@ -582,7 +582,7 @@ FileHeader:
  Data:    ELFDATA2LSB
  Type:    ET_REL
  Machine: EM_X86_64
  SHOff:    0xffffffffffffffff
  EShOff:  0xffffffffffffffff

## Check that llvm-objdump reports an error when it tries to dump a
## symbol name and .strtab is empty.
@@ -646,7 +646,7 @@ FileHeader:
  Type:      ET_REL
  Machine:   EM_X86_64
## SHN_XINDEX == 0xffff.
  SHStrNdx: 0xffff
  EShStrNdx: 0xffff
Sections:
  - Type: SHT_NULL
    Link: 0xff
+2 −2
Original line number Diff line number Diff line
@@ -23,8 +23,8 @@ FileHeader:
  Machine: EM_X86_64
## We simulate no section header table by
## overriding the ELF header properties.
  SHOff:   0x0
  SHNum:   0x0
  EShOff:  0x0
  EShNum:  0x0
Sections:
  - Name:    .rela.dyn
    Type:    SHT_RELA
Loading