[llvm-commits] LLD: patch WriterELF patch

Nick Kledzik kledzik at apple.com
Tue Sep 4 14:03:35 PDT 2012


On Sep 4, 2012, at 12:30 PM, Hemant Kulkarni wrote:
>    WriterOptionsELF();
>    
> +  enum OutputKind {
> +    outputDynamicExecutable,  // ET_EXEC
> +    outputStaticExecutable,   // ET_EXEC
> +    outputObjectFile,         // ET_REL
> +    outputDylib,              // ET_DYN
> +  };
> +  
> +  enum Architecture {
> +    arch_x86_64,
> +    arch_x86,
> +    arch_armv6,
> +    arch_armv7,
> +    arch_hexagon,
> +  };
These enums make sense for mach-o, but they may not make sense for ELF.  Mach-o uses a cpu-type and sub-type pair for architectures.  You may be able to use the standard values for e_machine and e_type and not invent a new enumeration.


> +  ///
> +  /// Create a specific instance of an architecture
> +  ///
> +  WriterOptionsELF(const Architecture arch,
> +                   const llvm::support::endianness endian,
> +                   const bool is64Bit);
> +  WriterOptionsELF(const OutputKind OK, const Architecture ARCH,
> +                   const bool REL,
> +                   const llvm::support::endianness endian,
> +                   const bool is64Bit);
> +  
> +  OutputKind   outputKind() const       { return _outputkind; }
> +  Architecture architecture() const     { return _architecture; }
> +  bool         is64Bit() const          { return _is64Bit; }
> +  llvm::support::endianness endianness() const { return _endian; }
> +  StringRef    archName() const;
> +  uint32_t     cpuType() const;
> +  uint32_t     cpuSubtype() const;
> +  bool         noTextRelocations() const { return _noTextRelocations; }
> +  bool         addEntryPointLoadCommand() const;
> +  bool         addUnixThreadLoadCommand() const;
The entrypoint and unix thread a mach-o specific options that have to do with which load commands are used.  

> +  StringRef    entryPointName() const;
> +  std::pair<llvm::support::endianness, bool>    getArchTypeClass() const;
> +
>  protected:
> +  OutputKind                _outputkind;
> +  Architecture              _architecture;
> +  bool                      _noTextRelocations;
> +  llvm::support::endianness _endian;
> +  bool                      _is64Bit;
> +  StringRef                 _customEntryPointName;
> +
>  };


> +template  <support::endianness target_endianness, bool is64Bits>
> +struct Elf_Ehdr {
> +    LLVM_ELF_IMPORT_TYPES(target_endianness, is64Bits)
> +    unsigned char e_ident[ELF::EI_NIDENT]; // ELF Identification bytes
> +    Elf_Half e_type;     // Type of file (see ET_*)
> +    Elf_Half e_machine;  // Required architecture for this file (see EM_*)
> +    Elf_Word e_version;  // Must be equal to 1
> +    Elf_Addr e_entry;    // Address to jump to in order to start program
> +    Elf_Off  e_phoff;    // Program header table's file offset, in bytes
> 

LLVM already has some structs for ELF data structures.  Can those be re-used? Or do they only work for reading ELF and not writing?  

I'm working on some changes for mach-o to better unify the reading and writing of load commands.  But I'm waiting to commit them until the testing infrastructure is set up to be able to add test cases.

-Nick








More information about the llvm-commits mailing list