[PATCH] D42839: [MC] Allow overriding whether to output Elf_Rel or Elf_Rela relocations
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 6 16:56:31 PST 2018
Alexander Richardson via Phabricator <reviews at reviews.llvm.org> writes:
> Index: lib/MC/MCELFObjectTargetWriter.cpp
> ===================================================================
> --- lib/MC/MCELFObjectTargetWriter.cpp
> +++ lib/MC/MCELFObjectTargetWriter.cpp
> @@ -8,14 +8,40 @@
> //===----------------------------------------------------------------------===//
>
> #include "llvm/MC/MCELFObjectWriter.h"
> +#include "llvm/Support/CommandLine.h"
>
> using namespace llvm;
>
> +enum class ELFRelocationFormat { Default, Rel, Rela };
> +static cl::opt<ELFRelocationFormat> RelocationFormat(
> + "elf-relocation-format",
> + cl::desc("Select whether to use REL or "
> + "RELA for relocations in the output object"),
> + cl::values(clEnumValN(ELFRelocationFormat::Default, "default",
> + "Use the default kind for the current target"),
> + clEnumValN(ELFRelocationFormat::Rel, "rel",
> + "Always emit REL relocations"),
> + clEnumValN(ELFRelocationFormat::Rela, "rela",
> + "Always emit RELA relocations")),
> + cl::init(ELFRelocationFormat::Default), cl::Hidden);
> +
> +static bool shouldUseRelocationAddend(bool Default) {
> + switch (RelocationFormat) {
> + case ELFRelocationFormat::Rel:
> + return false;
> + case ELFRelocationFormat::Rela:
> + return true;
> + default:
> + return Default;
> + }
> +}
Do you need to be able to force the use of Elf_Rel?
The only non test uses I can think of require forcing a target that
normally uses Elf_Rel to use Elf_Rela.
> MCELFObjectTargetWriter::MCELFObjectTargetWriter(bool Is64Bit_, uint8_t OSABI_,
> uint16_t EMachine_,
> bool HasRelocationAddend_)
> : OSABI(OSABI_), EMachine(EMachine_),
> - HasRelocationAddend(HasRelocationAddend_), Is64Bit(Is64Bit_) {}
> + HasRelocationAddend(shouldUseRelocationAddend(HasRelocationAddend_)),
> + Is64Bit(Is64Bit_) {}
You should probably move the option up the call chain and just pass the
final values of HasRelocationAddend_ to the constructor.
Cheers,
Rafael
More information about the llvm-commits
mailing list