[PATCH] D52749: [LLD][COFF] Fix CRT global initializers

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 2 09:15:09 PDT 2018


aganea added inline comments.


================
Comment at: COFF/Writer.cpp:1605
+        case 1:
+          return false;
+        case 0:
----------------
aganea wrote:
> mstorsjo wrote:
> > mstorsjo wrote:
> > > Won't this override the internal ordering based on the section name suffixes like .CRT$ABC?
> > Or what actually does `getBufferIdentifier()` return - the name of the object file? In that case I'd say this is wrong. If it returns the section name it might be ok...
> @mstorsjo `getBufferIdentifier()` indeed returns the file name. However at this point, chunks were already grouped by specific section. Meaning that this function will sort only, say, `.CRT$XCU` chunks at once. Internal TU order is guaranteed by the test below (`return SA->SectionNumber < SB->SectionNumber;`)
> 
> The only side-effect I could see is that this change makes **deterministic **initialization of global initializers (which in this case, means the TUs will be called in lexicographic order, based on their relative/absolute path and filename). The C++ std says the behavior is "indefinite", but this makes it "definite", at least for LLD. What is your stance on this? @ruiu @zturner @pcc @rnk 
In an ideal world, it'd be nice if this behavior could be randomized, with a command-line flag. That could trap some (global initialization) issues earlier in the target program, by successive "link"-"run program" runs.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D52749





More information about the llvm-commits mailing list