unix/linux: update to glibc 2.36

Support for LoongArch has been merged upstream. This allows to
drop the loong64 specific glibc patches.

Because the header file sys/mount.h of glibc 2.36 includes fcntl.h
(commit 78a408ee7ba041fc8d5dbd5f67065b4a982c11e5), this will leads to
duplicate definition of structure stat on MIPS64.  In order to solve
this error, use the custom type my_stat to generate the Go Stat_t.

Change-Id: I888280d777d1c7089548acf1b3821762011d79b0
Reviewed-on: https://go-review.googlesource.com/c/sys/+/453555
Reviewed-by: xiaodong liu <teaofmoli@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
diff --git a/unix/linux/Dockerfile b/unix/linux/Dockerfile
index 59c2ada..76aa837 100644
--- a/unix/linux/Dockerfile
+++ b/unix/linux/Dockerfile
@@ -17,14 +17,8 @@
 RUN git config --global advice.detachedHead false
 # Linux Kernel: Released 11 Dec 2022
 RUN git clone --branch v6.1 --depth 1 https://kernel.googlesource.com/pub/scm/linux/kernel/git/torvalds/linux
-# GNU C library: Released 03 Feb 2022
-RUN git clone --branch release/2.35/master --depth 1 https://sourceware.org/git/glibc.git
-
-# Only for loong64, add kernel and glibc patch
-RUN git clone https://github.com/loongson/golang-infra.git /git/loong64-patches \
-    && git config --global user.name "golang" && git config --global user.email "golang@localhost" \
-    && cd /git/loong64-patches && git checkout glibc-v2.35 && cd /git/glibc && git am /git/loong64-patches/*.patch \
-    && curl -fsSL https://git.savannah.gnu.org/cgit/config.git/plain/config.sub -o /git/glibc/scripts/config.sub
+# GNU C library: Released 30 Jul 2022
+RUN git clone --branch release/2.36/master --depth 1 https://sourceware.org/git/glibc.git
 
 # Get Go
 ENV GOLANG_VERSION 1.20rc2
diff --git a/unix/linux/mkall.go b/unix/linux/mkall.go
index 8c773d9..f849e1a 100644
--- a/unix/linux/mkall.go
+++ b/unix/linux/mkall.go
@@ -411,7 +411,16 @@
 
 	// Make the glibc headers we need for this architecture
 	confScript := filepath.Join(GlibcDir, "configure")
-	glibcConf := t.makeCommand(confScript, "--prefix="+filepath.Join(TempDir, t.GoArch), "--host="+t.GNUArch, "--enable-kernel="+MinKernel)
+	glibcArgs := []string{"--prefix=" + filepath.Join(TempDir, t.GoArch), "--host=" + t.GNUArch}
+	if t.LinuxArch == "loongarch" {
+		// The minimum version requirement of the Loongarch for the kernel in glibc
+		// is 5.19, if --enable-kernel is less than 5.19, glibc handles errors
+		glibcArgs = append(glibcArgs, "--enable-kernel=5.19.0")
+	} else {
+		glibcArgs = append(glibcArgs, "--enable-kernel="+MinKernel)
+	}
+	glibcConf := t.makeCommand(confScript, glibcArgs...)
+
 	glibcConf.Dir = buildDir
 	if err := glibcConf.Run(); err != nil {
 		return err
diff --git a/unix/linux/types.go b/unix/linux/types.go
index f24909e..3855ce3 100644
--- a/unix/linux/types.go
+++ b/unix/linux/types.go
@@ -21,6 +21,7 @@
 #define _GNU_SOURCE
 
 #include <dirent.h>
+#include <fcntl.h>
 #include <poll.h>
 #include <sched.h>
 #include <signal.h>
@@ -50,6 +51,7 @@
 #include <sys/timerfd.h>
 #include <sys/times.h>
 #include <sys/timex.h>
+#include <sys/types.h>
 #include <sys/un.h>
 #include <sys/user.h>
 #include <sys/utsname.h>
@@ -156,7 +158,7 @@
 //	  struct (like st_atim) for consistency with the glibc fields.
 //	* The padding fields get different names to not break compatibility.
 //	* st_blocks is signed, again for compatibility.
-struct stat {
+typedef struct {
 	unsigned int		st_dev;
 	unsigned int		st_pad1[3]; // Reserved for st_dev expansion
 
@@ -183,18 +185,9 @@
 	unsigned int		st_pad4;
 
 	long			st_blocks;
-};
-
-// These are needed because we do not include fcntl.h or sys/types.h
-#include <linux/fcntl.h>
-#include <linux/fadvise.h>
-
+} my_stat;
 #else
-
-// Use the stat defined by glibc
-#include <fcntl.h>
-#include <sys/types.h>
-
+typedef struct stat my_stat;
 #endif
 
 // These are defined in linux/fcntl.h, but including it globally causes
@@ -510,7 +503,7 @@
 
 // Files
 
-type Stat_t C.struct_stat
+type Stat_t C.my_stat
 
 type StatxTimestamp C.struct_statx_timestamp
 
diff --git a/unix/zerrors_linux.go b/unix/zerrors_linux.go
index 35de885..e174685 100644
--- a/unix/zerrors_linux.go
+++ b/unix/zerrors_linux.go
@@ -1814,6 +1814,7 @@
 	MADV_DONTDUMP                               = 0x10
 	MADV_DONTFORK                               = 0xa
 	MADV_DONTNEED                               = 0x4
+	MADV_DONTNEED_LOCKED                        = 0x18
 	MADV_FREE                                   = 0x8
 	MADV_HUGEPAGE                               = 0xe
 	MADV_HWPOISON                               = 0x64