[PATCH] [ELF] Allow customization of OutputELFWriter class

Simon Atanasyan simon at atanasyan.com
Tue Apr 7 16:13:31 PDT 2015


Hi shankar.easwaran, ruiu,

Now target specific code inherits writer classes from `ExecutableWriter` and `DynamicLibraryWriter`. It is OK unitil we need to add some target specific functionality which is common to both executable and dynamic library writers. We have to either duplicate such code or move it to utility routine.                                                        
                                                                        
The patch tries to solve this problem using some sort of template trick. Both `ExecutableWriter` and `DynamicLibraryWriter` classes get one more template argument `BaseWriter` and use it as a base class. By default this argument has `OutputELFWriter<ELFT>` so we get the same code as now. If we need to share some code amont executable and dynamic library writers we create new class (for example `MipsOutputWriter`) inherited from `OutputWriter` and put common code to this class. Then we create writer as in example below:

```
template <class ELFT>
class MipsExecutableWriter
    : public ExecutableWriter<ELFT, MipsOutputWriter<ELFT>> {
...
};

template <class ELFT>
using MipsDynamicLibraryWriter =
    DynamicLibraryWriter<ELFT, MipsOutputWriter<ELFT>>;
```

The patch makes some part of code more complicated but reduces code size and prevent code duplication.

Any objections and / or comments?

REPOSITORY
  rL LLVM

http://reviews.llvm.org/D8882

Files:
  lib/ReaderWriter/ELF/AArch64/AArch64DynamicLibraryWriter.h
  lib/ReaderWriter/ELF/AArch64/AArch64ExecutableWriter.h
  lib/ReaderWriter/ELF/AArch64/AArch64TargetHandler.cpp
  lib/ReaderWriter/ELF/DynamicLibraryWriter.h
  lib/ReaderWriter/ELF/ExecutableWriter.h
  lib/ReaderWriter/ELF/Hexagon/HexagonDynamicLibraryWriter.h
  lib/ReaderWriter/ELF/Hexagon/HexagonExecutableWriter.h
  lib/ReaderWriter/ELF/Hexagon/HexagonLinkingContext.h
  lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.cpp
  lib/ReaderWriter/ELF/Hexagon/HexagonTargetHandler.h
  lib/ReaderWriter/ELF/Mips/MipsDynamicLibraryWriter.h
  lib/ReaderWriter/ELF/Mips/MipsELFWriters.h
  lib/ReaderWriter/ELF/Mips/MipsExecutableWriter.h
  lib/ReaderWriter/ELF/X86/X86DynamicLibraryWriter.h
  lib/ReaderWriter/ELF/X86_64/X86_64DynamicLibraryWriter.h
  lib/ReaderWriter/ELF/X86_64/X86_64ExecutableWriter.h
  lib/ReaderWriter/ELF/X86_64/X86_64TargetHandler.cpp
  test/elf/Mips/gp-sym-1-micro.test
  test/elf/Mips/gp-sym-1.test
  test/elf/Mips/mips-options-gp0.test
  test/elf/Mips/rel-gprel16.test
  test/elf/Mips/rel-gprel32.test

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8882.23378.patch
Type: text/x-patch
Size: 45307 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150407/ef8d9b00/attachment.bin>


More information about the llvm-commits mailing list