On Thu, 2 Aug 2018, Liu Hao wrote:

在 2018/8/2 19:02, Martin Storsjö 写道:
-#ifdef __clang__
  extern func_ptr __CTOR_END__[];
  extern func_ptr __DTOR_END__[];

  void __do_global_ctors (void)
  {
    static func_ptr *p = __CTOR_END__ - 1;
+  // If the linker provided its own __CTOR_LIST__ in addition to the one
+  // we provide, we'd actually stop at __CTOR_LIST__+1, but that's no problem
+  // for this function.
    while (*p != (func_ptr) -1) {
      (*(p))();

At the very firsts iteration, isn't `*p` null if there are two null termini in the list?

(i.e. the list looks like `-1, -1, ... some `func_ptr`s ... , 0, 0`)

I thought the same; that's why I did the extra check with "if (*p)", as I mentioned in the other mail.

However, in practice, __CTOR_END__ points to the first 0-terminator. Not sure why that is, but you can check with -Wl,-Map,map.txt.

But yes, it's safer with that extra check added, then both iterations should be fine, regardless which one the symbol points to, in both ends.

// Martin
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to