On Wed, Sep 13, 2017 at 08:44:24AM +0000, Miod Vallat wrote: > > > Forcing uextraloc into .data via > > int uextraloc __attribute__ ((section(".data"))) = 0; > > avoids the crashes. > > Regardless of this bug, the in-tree gcc was modified to default to put > explicitly zero initialized data in .data rather than .bss, i.e. default > to -fno-zero-initialized-in-bss. > > It might be wise to make the default configuration of clang follow this > behaviour as well. >
Yes, that seems reasonable. Index: gnu/llvm/tools/clang/lib/Driver/Tools.cpp =================================================================== RCS file: /cvs/src/gnu/llvm/tools/clang/lib/Driver/Tools.cpp,v retrieving revision 1.14 diff -u -p -r1.14 Tools.cpp --- gnu/llvm/tools/clang/lib/Driver/Tools.cpp 28 Jul 2017 15:31:54 -0000 1.14 +++ gnu/llvm/tools/clang/lib/Driver/Tools.cpp 13 Sep 2017 09:51:50 -0000 @@ -4463,8 +4463,13 @@ void Clang::ConstructJob(Compilation &C, if (shouldUseFramePointer(Args, getToolChain().getTriple())) CmdArgs.push_back("-mdisable-fp-elim"); + + bool ZeroInitializedInBSSDefault = true; + if (getToolChain().getTriple().isOSOpenBSD()) + ZeroInitializedInBSSDefault = false; if (!Args.hasFlag(options::OPT_fzero_initialized_in_bss, - options::OPT_fno_zero_initialized_in_bss)) + options::OPT_fno_zero_initialized_in_bss, + ZeroInitializedInBSSDefault)) CmdArgs.push_back("-mno-zero-initialized-in-bss"); bool OFastEnabled = isOptimizationLevelFast(Args); Index: share/man/man1/clang-local.1 =================================================================== RCS file: /cvs/src/share/man/man1/clang-local.1,v retrieving revision 1.9 diff -u -p -r1.9 clang-local.1 --- share/man/man1/clang-local.1 29 Jul 2017 21:01:13 -0000 1.9 +++ share/man/man1/clang-local.1 13 Sep 2017 09:57:14 -0000 @@ -95,6 +95,14 @@ and .Xr free 3 builtins are disabled to prevent undesriable optimizations of calls to these functions. +.It +.Nm clang +will not move variables initialized with the value zero from the data section +to the bss section. +The default behaviour of +.Nm clang +on other systems is to perform this action, which can be restored with +.Fl fzero-initialized-in-bss . .El .Sh SEE ALSO .Xr clang 1