[PATCH] D34355: [LLD][ELF] Define _GLOBAL_OFFSET_TABLE_ to base of .got for ARM
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 19 13:42:24 PDT 2017
Peter Smith via Phabricator <reviews at reviews.llvm.org> writes:
> Index: ELF/Writer.cpp
> ===================================================================
> --- ELF/Writer.cpp
> +++ ELF/Writer.cpp
> @@ -825,9 +825,16 @@
> // The situation is even stranger on x86_64 where the assembly doesn't
> // need the magical symbol, but gas still puts _GLOBAL_OFFSET_TABLE_ as
> // an undefined symbol in the .o files.
> - // Given that the symbol is effectively unused, we just create a dummy
> - // hidden one to avoid the undefined symbol error.
> - Symtab<ELFT>::X->addIgnored("_GLOBAL_OFFSET_TABLE_");
> + // For ARM the clang assembler may not have treated _GLOBAL_OFFSET_TABLE_ as
> + // special so we may encounter a R_ARM_REL32 to _GLOBAL_OFFSET_TABLE_ which
> + // will only evaluate correctly if _GLOBAL_OFFSET_TABLE_ is at the base of the
> + // .got section. for other architectures, given that the symbol is
> + // effectively unused, we just create a dummy hidden one to avoid the
> + // undefined symbol error.
> + if (Config->EMachine == EM_ARM && InX::Got)
> + addOptionalRegular<ELFT>("_GLOBAL_OFFSET_TABLE_", InX::Got, 0);
> + else
> + Symtab<ELFT>::X->addIgnored("_GLOBAL_OFFSET_TABLE_");
Looking at the llvm side, I kept wondering why do ABIs even have
relocations like R_386_GOTPC. Why not just have linker defined symbols
_GLOBAL_OFFSET_TABLE_ and _GLOBAL_OFFSET_TABLE_END_?
I also found more cases where MC doesn't convert _GLOBAL_OFFSET_TABLE_,
so think I am not that opposed to something like this, but I would change
it a bit. _GLOBAL_OFFSET_TABLE_ should always point to the start or end
of the got depending on the architecture.
Cheers,
Rafael
More information about the llvm-commits
mailing list