[lld] r190840 - [lld][ELF] Assign sectionChoice properly to ELF atoms
Nick Kledzik
kledzik at apple.com
Mon Sep 16 21:34:45 PDT 2013
Thanks!
On Sep 16, 2013, at 7:56 PM, Shankar Easwaran wrote:
> Author: shankare
> Date: Mon Sep 16 21:56:22 2013
> New Revision: 190840
>
> URL: http://llvm.org/viewvc/llvm-project?rev=190840&view=rev
> Log:
> [lld][ELF] Assign sectionChoice properly to ELF atoms
>
> This sets the sectionChoice property for DefinedAtoms. The output section name
> is derived by the property of the atom. This also decreases native file size.
>
> Adds a test.
>
> Added:
> lld/trunk/test/elf/X86_64/sectionchoice.test
> Modified:
> lld/trunk/lib/ReaderWriter/ELF/Atoms.h
> lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
> lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
> lld/trunk/test/elf/mergeconstants.test
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/Atoms.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Atoms.h?rev=190840&r1=190839&r2=190840&view=diff
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/Atoms.h (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/Atoms.h Mon Sep 16 21:56:22 2013
> @@ -16,6 +16,7 @@
> #include "lld/ReaderWriter/Simple.h"
>
> #include "llvm/ADT/ArrayRef.h"
> +#include "llvm/ADT/StringSwitch.h"
>
> #include <memory>
> #include <vector>
> @@ -376,9 +377,20 @@ public:
>
> // Do we have a choice for ELF? All symbols live in explicit sections.
> virtual SectionChoice sectionChoice() const {
> - if (_symbol->st_shndx > llvm::ELF::SHN_LORESERVE)
> - return sectionBasedOnContent;
> -
> + switch (contentType()) {
> + case typeCode:
> + case typeData:
> + case typeZeroFill:
> + case typeThreadZeroFill:
> + case typeThreadData:
> + case typeConstant:
> + if ((_sectionName == ".text") || (_sectionName == ".data") ||
> + (_sectionName == ".bss") || (_sectionName == ".rodata") ||
> + (_sectionName == ".tdata") || (_sectionName == ".tbss"))
> + return sectionBasedOnContent;
> + default:
> + break;
> + }
> return sectionCustomRequired;
> }
>
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h?rev=190840&r1=190839&r2=190840&view=diff
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h Mon Sep 16 21:56:22 2013
> @@ -172,8 +172,7 @@ public:
> int32_t contentPermissions);
>
> /// \brief This maps the input sections to the output section names
> - virtual StringRef getSectionName(StringRef name, const int32_t contentType,
> - const int32_t contentPermissions);
> + virtual StringRef getSectionName(const DefinedAtom *da) const;
>
> /// \brief Gets or creates a section.
> AtomSection<ELFT> *getSection(
> @@ -372,29 +371,35 @@ Layout::SectionOrder DefaultLayout<ELFT>
>
> /// \brief This maps the input sections to the output section names
> template <class ELFT>
> -StringRef DefaultLayout<ELFT>::getSectionName(
> - StringRef name, const int32_t contentType,
> - const int32_t contentPermissions) {
> - if ((contentType == DefinedAtom::typeZeroFill) ||
> - (contentType == DefinedAtom::typeZeroFillFast))
> - return ".bss";
> - if (name.startswith(".text"))
> - return ".text";
> - if (name.startswith(".rodata"))
> - return ".rodata";
> - if (name.startswith(".gcc_except_table"))
> - return ".gcc_except_table";
> - if (name.startswith(".data.rel.ro"))
> - return ".data.rel.ro";
> - if (name.startswith(".data.rel.local"))
> - return ".data.rel.local";
> - if (name.startswith(".data"))
> - return ".data";
> - if (name.startswith(".tdata"))
> - return ".tdata";
> - if (name.startswith(".tbss"))
> - return ".tbss";
> - return name;
> +StringRef DefaultLayout<ELFT>::getSectionName(const DefinedAtom *da) const {
> + if (da->sectionChoice() == DefinedAtom::sectionBasedOnContent) {
> + switch (da->contentType()) {
> + case DefinedAtom::typeCode:
> + return ".text";
> + case DefinedAtom::typeData:
> + return ".data";
> + case DefinedAtom::typeConstant:
> + return ".rodata";
> + case DefinedAtom::typeZeroFill:
> + return ".bss";
> + case DefinedAtom::typeThreadData:
> + return ".tdata";
> + case DefinedAtom::typeThreadZeroFill:
> + return ".tbss";
> + default:
> + break;
> + }
> + }
> + return llvm::StringSwitch<StringRef>(da->customSectionName())
> + .StartsWith(".text", ".text")
> + .StartsWith(".rodata", ".rodata")
> + .StartsWith(".gcc_except_table", ".gcc_except_table")
> + .StartsWith(".data.rel.ro", ".data.rel.ro")
> + .StartsWith(".data.rel.local", ".data.rel.local")
> + .StartsWith(".data", ".data")
> + .StartsWith(".tdata", ".tdata")
> + .StartsWith(".tbss", ".tbss")
> + .Default(da->customSectionName());
> }
>
> /// \brief Gets the segment for a output section
> @@ -519,12 +524,11 @@ ErrorOr<const lld::AtomLayout &> Default
> // -noinhibit-exec.
> if (definedAtom->contentType() == DefinedAtom::typeUnknown)
> return make_error_code(llvm::errc::invalid_argument);
> - StringRef sectionName = definedAtom->customSectionName();
> const DefinedAtom::ContentPermissions permissions =
> definedAtom->permissions();
> const DefinedAtom::ContentType contentType = definedAtom->contentType();
>
> - sectionName = getSectionName(sectionName, contentType, permissions);
> + StringRef sectionName = getSectionName(definedAtom);
> AtomSection<ELFT> *section =
> getSection(sectionName, contentType, permissions);
> // Add runtime relocations to the .rela section.
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h?rev=190840&r1=190839&r2=190840&view=diff
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h Mon Sep 16 21:56:22 2013
> @@ -103,13 +103,15 @@ public:
> }
>
> /// \brief This maps the input sections to the output section names
> - virtual StringRef getSectionName(StringRef name, const int32_t contentType,
> - const int32_t contentPermissions) {
> - if ((contentType == DefinedAtom::typeDataFast) ||
> - (contentType == DefinedAtom::typeZeroFillFast))
> + virtual StringRef getSectionName(const DefinedAtom *da) const {
> + switch (da->contentType()) {
> + case DefinedAtom::typeDataFast:
> + case DefinedAtom::typeZeroFillFast:
> return ".sdata";
> - return DefaultLayout<HexagonELFType>::getSectionName(name, contentType,
> - contentPermissions);
> + default:
> + break;
> + }
> + return DefaultLayout<HexagonELFType>::getSectionName(da);
> }
>
> /// \brief Gets or creates a section.
>
> Added: lld/trunk/test/elf/X86_64/sectionchoice.test
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/X86_64/sectionchoice.test?rev=190840&view=auto
> ==============================================================================
> --- lld/trunk/test/elf/X86_64/sectionchoice.test (added)
> +++ lld/trunk/test/elf/X86_64/sectionchoice.test Mon Sep 16 21:56:22 2013
> @@ -0,0 +1,7 @@
> +# This tests that we are able to properly set the sectionChoice for DefinedAtoms
> +RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/zerosizedsection.o \
> +RUN: --noinhibit-exec -o %t -emit-yaml
> +RUN: FileCheck %s < %t
> +
> +CHECK-NOT: section-choice: sectionCustomRequired
> +
>
> Modified: lld/trunk/test/elf/mergeconstants.test
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/mergeconstants.test?rev=190840&r1=190839&r2=190840&view=diff
> ==============================================================================
> --- lld/trunk/test/elf/mergeconstants.test (original)
> +++ lld/trunk/test/elf/mergeconstants.test Mon Sep 16 21:56:22 2013
> @@ -12,8 +12,6 @@ mergeAtoms: scope: global
> mergeAtoms: type: data
> mergeAtoms: content: [ 00, 00, 00, 00, 00, 00, 00, 00 ]
> mergeAtoms: alignment: 2^3
> -mergeAtoms: section-choice: custom-required
> -mergeAtoms: section-name: .data
> mergeAtoms: references:
> mergeAtoms: - kind: R_X86_64_64
> mergeAtoms: offset: 3
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list