[PATCH] D34326: [ELF] - Support SORT_BY_INIT_PRIORITY for .ctors.*/.dtors sections in linkerscript.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 19 12:41:37 PDT 2017


grimar added a comment.

In https://reviews.llvm.org/D34326#784305, @ruiu wrote:

> I don't know if we need this, as it implements a feature that is different from what the manual says, and no one is complaining about this.


I think I got it. Manual says order is ascending, and that is true. Feature should implement what manual says,
And gnu linkers do that, but we don't, because priorities for sections are encoded differently:
(lib\CodeGen\TargetLoweringObjectFileImpl.cpp)

  static MCSectionELF *getStaticStructorSection(MCContext &Ctx, bool UseInitArray,
                                                bool IsCtor, unsigned Priority,
                                                const MCSymbol *KeySym) {
  ...
    if (UseInitArray) {
      if (IsCtor) {
        Type = ELF::SHT_INIT_ARRAY;
        Name = ".init_array";
      } else {
        Type = ELF::SHT_FINI_ARRAY;
        Name = ".fini_array";
      }
      if (Priority != 65535) {
        Name += '.';
        Name += utostr(Priority);
      }
    } else {
      // The default scheme is .ctor / .dtor, so we have to invert the priority
      // numbering.
      if (IsCtor)
        Name = ".ctors";
      else
        Name = ".dtors";
      if (Priority != 65535) {
        Name += '.';
        Name += utostr(65535 - Priority);
      }
      Type = ELF::SHT_PROGBITS;
    }

So according to above I think we should:

1. Sort priorities in accending order, we already do that, but:

a) We do that correctly for .init/fini_array's
b) Do not do that correctly for .[cd]tors because before sorting should find Priority which is 65535 - value we use as priority now.



================
Comment at: ELF/LinkerScript.cpp:240
+  uint64_t ValX, ValY;
+  if (to_integer(X.trim('0'), ValX, 10) && to_integer(Y.trim('0'), ValY, 10))
+    if (ValX != ValY)
----------------
ruiu wrote:
> `trim()` trims the character both from both ends. That's probably not what you want.
Oh, right. I want to use ltrim here. I was mithinking about what trim do, thanks.


https://reviews.llvm.org/D34326





More information about the llvm-commits mailing list