https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61502
--- Comment #20 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Alexander Cherepanov from comment #19) > (In reply to jos...@codesourcery.com from comment #3) > > Except within a larger object, I'm not aware of any reason the cases of > > two objects following or not following each other in memory must be > > mutually exclusive. > > Apparently some folks use linker scripts to get a specific arrangement of > objects. > > A fresh example is a problem in Linux -- https://lkml.org/lkml/2016/6/25/77 > . A simplified example from http://pastebin.com/4Qc6pUAA : > > extern int __start[]; > extern int __end[]; > > extern void bar(int *); > > void foo() > { > for (int *x = __start; x != __end; ++x) > bar(x); > } To get around the above example: extern int __start[]; extern int __end[]; extern void bar(int *); void foo() { int *x = __start; int *y = __end; asm("":"+r"(x)); asm("":"+r"(y)); for (; x != y; ++x) bar(x); } > > This is optimized into an infinite loop by gcc 7 at -O.