@@ -728,13 +728,21 @@ const (
728
728
_GoidCacheBatch = 16
729
729
)
730
730
731
- // cpuinit sets up CPU feature flags and calls internal/cpu.Initialize. env should be the complete
732
- // value of the GODEBUG environment variable.
733
- func cpuinit (env string ) {
731
+ // cpuinit sets up CPU feature flags and calls internal/cpu.Initialize.
732
+ func cpuinit () {
734
733
switch GOOS {
735
734
case "aix" , "darwin" , "ios" , "dragonfly" , "freebsd" , "netbsd" , "openbsd" , "illumos" , "solaris" , "linux" :
736
735
cpu .DebugOptions = true
737
736
}
737
+
738
+ // find GODEBUG in envs
739
+ var env string // env should be the complete value of the GODEBUG environment variable.
740
+ for _ , value := range envs {
741
+ if stringslite .HasPrefix (value , "GODEBUG=" ) {
742
+ env = value
743
+ break
744
+ }
745
+ }
738
746
cpu .Initialize (env )
739
747
740
748
// Support cpu feature variables are used in code generated by the compiler
@@ -753,49 +761,6 @@ func cpuinit(env string) {
753
761
}
754
762
}
755
763
756
- // getGodebugEarly extracts the environment variable GODEBUG from the environment on
757
- // Unix-like operating systems and returns it. This function exists to extract GODEBUG
758
- // early before much of the runtime is initialized.
759
- func getGodebugEarly () string {
760
- const prefix = "GODEBUG="
761
- var env string
762
- switch GOOS {
763
- case "aix" , "darwin" , "ios" , "dragonfly" , "freebsd" , "netbsd" , "openbsd" , "illumos" , "solaris" , "linux" :
764
- // Similar to goenv_unix but extracts the environment value for
765
- // GODEBUG directly.
766
- // TODO(moehrmann): remove when general goenvs() can be called before cpuinit()
767
-
768
- // If the binary is an archive or a library, the operating system is Linux,
769
- // and the system uses Musl, then read the environment variables from the
770
- // /proc/self/environ file. Iterate over each null-terminated string read
771
- // from the file. If any string has the specified prefix, return that string.
772
- if (isarchive || islibrary ) && GOOS == "linux" && isMusl () {
773
- for _ , value := range readNullTerminatedStringsFromFile (procEnviron ) {
774
- if stringslite .HasPrefix (value , prefix ) {
775
- return value
776
- }
777
- }
778
- return env
779
- }
780
-
781
- n := int32 (0 )
782
- for argv_index (argv , argc + 1 + n ) != nil {
783
- n ++
784
- }
785
-
786
- for i := int32 (0 ); i < n ; i ++ {
787
- p := argv_index (argv , argc + 1 + i )
788
- s := unsafe .String (p , findnull (p ))
789
-
790
- if stringslite .HasPrefix (s , prefix ) {
791
- env = gostring (p )[len (prefix ):]
792
- break
793
- }
794
- }
795
- }
796
- return env
797
- }
798
-
799
764
// The bootstrap sequence is:
800
765
//
801
766
// call osinit
@@ -841,10 +806,10 @@ func schedinit() {
841
806
moduledataverify ()
842
807
stackinit ()
843
808
mallocinit ()
844
- godebug := getGodebugEarly ()
845
- cpuinit (godebug ) // must run before alginit
846
- randinit () // must run before alginit, mcommoninit
847
- alginit () // maps, hash, rand must not be used before this call
809
+ goenvs ()
810
+ cpuinit () // must run before alginit
811
+ randinit () // must run before alginit, mcommoninit
812
+ alginit () // maps, hash, rand must not be used before this call
848
813
mcommoninit (gp .m , - 1 )
849
814
modulesinit () // provides activeModules
850
815
typelinksinit () // uses maps, activeModules
@@ -855,7 +820,6 @@ func schedinit() {
855
820
initSigmask = gp .m .sigmask
856
821
857
822
goargs ()
858
- goenvs ()
859
823
secure ()
860
824
checkfds ()
861
825
parsedebugvars ()
0 commit comments