[PATCH] D35509: Covnert .[cd]tors to .{init, fini}_array using synthetic section.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 7 09:37:07 PST 2017


Rui Ueyama via Phabricator <reviews at reviews.llvm.org> writes:

> +template <class T> static void reverseCopy(uint8_t *To, ArrayRef<T> From) {
> +  T *Buf = (T *)To;
> +  for (const T &Data : llvm::reverse(From))
> +    *Buf++ = Data;

I think you have to use a memcpy to not break strict aliasing rules.

> Index: lld/ELF/OutputSections.cpp
> ===================================================================
> --- lld/ELF/OutputSections.cpp
> +++ lld/ELF/OutputSections.cpp
> @@ -493,66 +493,6 @@
>    Flags |= SHF_INFO_LINK;
>  }
>  
> -// Returns true if S matches /Filename.?\.o$/.
> -static bool isCrtBeginEnd(StringRef S, StringRef Filename) {
> -  if (!S.endswith(".o"))
> -    return false;
> -  S = S.drop_back(2);
> -  if (S.endswith(Filename))
> -    return true;
> -  return !S.empty() && S.drop_back().endswith(Filename);
> -}
> -
> -static bool isCrtbegin(StringRef S) { return isCrtBeginEnd(S, "crtbegin"); }
> -static bool isCrtend(StringRef S) { return isCrtBeginEnd(S, "crtend"); }

You still need to consider these, no? You can probably map them to
lowest and highest priority.

Given that all BSDs have init_array implemented, I agree that this is a
reasonable direction to go. That way when time comes to write a new
linker a decade or two from now it can hopefully ignore .ctors.

Cheers,
Rafael


More information about the llvm-commits mailing list