[PATCH] ELF: Move relocation predicates out of the context class.

Rui Ueyama ruiu at google.com
Thu Feb 12 21:28:27 PST 2015


Looks like each subdirectory in ELF directory was created as a copy of
some architecture (x86_64 perhaps?) as a template. They contain many
similar-looking code. They are not always identical since they diverged
over time. Some differences between the subdirectories are real, and
some are not but just different.

A patch for ELF often has to update multiple occurrences of
similar-looking code in the subdirectories. r228905 is an example.
This is not a good shape. It's probably time to visit all subdirectories,
and if there's architecture-independent stuff there, move that to the
ELF parent directory.

This patch is a starter. This is not totally architecture-independent
since relocations depend on architecture types, but this reduces the
amount of code from the subdirectories and also cut dependencies between
code, so I think it's not bad as a starter. After submitting this,
we have less code there, which makes it easier to find code duplicates.

We have bunch of predicates for relocations for questions like "is
this relocation is for PLT?" We can say whether a relocation is a PLT
or not, for example, by just looking at the relocation. Currently the
predicates are members of LinkingContext, but no context is needed to
answer to that question. And in general if we can make the same decision
by looking at not both X and Y but only X, the latter is preferred.

It is now clear that some architectures didn't define some predicates.
For example, x86 didn't have a predicate function for the copy relocation.
I think this is a missing feature, we may want to revisit that later.

By moving the code out of LinkingContext, each <arch>LinkingContext
becomes smaller, which helps find duplicates in the subdirectories.

http://reviews.llvm.org/D7605

Files:
  include/lld/ReaderWriter/ELFLinkingContext.h
  lib/ReaderWriter/ELF/AArch64/AArch64LinkingContext.h
  lib/ReaderWriter/ELF/Atoms.cpp
  lib/ReaderWriter/ELF/Atoms.h
  lib/ReaderWriter/ELF/CMakeLists.txt
  lib/ReaderWriter/ELF/DefaultLayout.h
  lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h
  lib/ReaderWriter/ELF/Mips/MipsLinkingContext.cpp
  lib/ReaderWriter/ELF/Mips/MipsLinkingContext.h
  lib/ReaderWriter/ELF/SectionChunks.h
  lib/ReaderWriter/ELF/X86/X86LinkingContext.h
  lib/ReaderWriter/ELF/X86_64/X86_64LinkingContext.h

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7605.19871.patch
Type: text/x-patch
Size: 18870 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150213/6d7c74d5/attachment.bin>


More information about the llvm-commits mailing list