From 46e553bd18cfbe39157b734433f5f81d542a9978 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 15 May 2012 15:25:47 -0700
Subject: [PATCH] Properly handle lib-names for x86-64 and x32

---
 ChangeLog.libnames                           |   14 +++
 Makeconfig                                   |    2 +-
 config.make.in                               |    2 +
 configure                                    |    6 ++
 configure.in                                 |    5 +
 sysdeps/unix/sysv/linux/i386/configure       |    4 +
 sysdeps/unix/sysv/linux/i386/configure.in    |    5 +
 sysdeps/unix/sysv/linux/x86_64/configure     |    4 +
 sysdeps/unix/sysv/linux/x86_64/configure.in  |    5 +
 sysdeps/unix/sysv/linux/x86_64/lib-names.awk |  122 ++++++++++++++++++++++++++
 10 files changed, 168 insertions(+), 1 deletions(-)
 create mode 100644 ChangeLog.libnames
 create mode 100644 sysdeps/unix/sysv/linux/i386/configure
 create mode 100644 sysdeps/unix/sysv/linux/i386/configure.in
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/configure
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/configure.in
 create mode 100644 sysdeps/unix/sysv/linux/x86_64/lib-names.awk

diff --git a/ChangeLog.libnames b/ChangeLog.libnames
new file mode 100644
index 0000000..d6eacdb
--- /dev/null
+++ b/ChangeLog.libnames
@@ -0,0 +1,14 @@
+2012-05-15  H.J. Lu  <hongjiu.lu@intel.com>
+
+	[BZ #14112]
+	* Makeconfig ($(common-objpfx)gnu/lib-names.stmp): Depend on
+	$(lib-names_awk) instead of scripts/lib-names.awk.
+	* config.make.in (lib-names_awk): New.
+	* configure.in (lib_names_awk): Set to scripts/lib-names.awk if
+	not set.  Substitute.
+	* sysdeps/unix/sysv/linux/i386/configure.in: New file.
+	* sysdeps/unix/sysv/linux/x86_64/configure.in: Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/lib-names.awk: Likewise.
+	* configure: Regenerated.
+	* sysdeps/unix/sysv/linux/i386/configure: Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/configure: Likewise.
diff --git a/Makeconfig b/Makeconfig
index f68a752..297fe2c 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -842,7 +842,7 @@ postclean-generated += soversions.mk soversions.i \
 before-compile += $(common-objpfx)gnu/lib-names.h
 ifeq ($(soversions.mk-done),t)
 $(common-objpfx)gnu/lib-names.h: $(common-objpfx)gnu/lib-names.stmp; @:
-$(common-objpfx)gnu/lib-names.stmp: $(..)scripts/lib-names.awk \
+$(common-objpfx)gnu/lib-names.stmp: $(..)$(lib-names_awk) \
 				    $(common-objpfx)soversions.i
 	$(make-target-directory)
 	@rm -f ${@:stmp=T} $@
diff --git a/config.make.in b/config.make.in
index 6c4d04e..e60afcf 100644
--- a/config.make.in
+++ b/config.make.in
@@ -76,6 +76,8 @@ oldest-abi = @oldest_abi@
 exceptions = @exceptions@
 multi-arch = @multi_arch@
 
+lib-names_awk = @lib_names_awk@
+
 mach-interface-list = @mach_interface_list@
 
 have-bash2 = @libc_cv_have_bash2@
diff --git a/configure b/configure
index 8b10f5a..33dcb40 100755
--- a/configure
+++ b/configure
@@ -607,6 +607,7 @@ ac_subst_vars='LTLIBOBJS
 LIBOBJS
 RELEASE
 VERSION
+lib_names_awk
 mach_interface_list
 DEFINES
 static_nss
@@ -7641,6 +7642,11 @@ $as_echo "$libc_cv_pic_default" >&6; }
 
 
 
+if test -z "${lib_names_awk}"; then
+  lib_names_awk=scripts/lib-names.awk
+fi
+
+
 if test "`(cd $srcdir; pwd)`" = "`pwd`"; then
   config_makefile=
 else
diff --git a/configure.in b/configure.in
index 30a062f..c321de5 100644
--- a/configure.in
+++ b/configure.in
@@ -2124,6 +2124,11 @@ AC_SUBST(DEFINES)
 dnl See sysdeps/mach/configure.in for this variable.
 AC_SUBST(mach_interface_list)
 
+if test -z "${lib_names_awk}"; then
+  lib_names_awk=scripts/lib-names.awk
+fi
+AC_SUBST(lib_names_awk)
+
 if test "`(cd $srcdir; pwd)`" = "`pwd`"; then
   config_makefile=
 else
diff --git a/sysdeps/unix/sysv/linux/i386/configure b/sysdeps/unix/sysv/linux/i386/configure
new file mode 100644
index 0000000..482a0b4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/i386/configure
@@ -0,0 +1,4 @@
+# This file is generated from configure.in by Autoconf.  DO NOT EDIT!
+ # Local configure fragment for sysdeps/unix/sysv/linux/x86_64.
+
+lib_names_awk=sysdeps/unix/sysv/linux/x86_64/lib-names.awk
diff --git a/sysdeps/unix/sysv/linux/i386/configure.in b/sysdeps/unix/sysv/linux/i386/configure.in
new file mode 100644
index 0000000..8009ee9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/i386/configure.in
@@ -0,0 +1,5 @@
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/unix/sysv/linux/x86_64.
+
+dnl Need to handle lib-names properly for x86-64 and x32.
+lib_names_awk=sysdeps/unix/sysv/linux/x86_64/lib-names.awk
diff --git a/sysdeps/unix/sysv/linux/x86_64/configure b/sysdeps/unix/sysv/linux/x86_64/configure
new file mode 100644
index 0000000..482a0b4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/configure
@@ -0,0 +1,4 @@
+# This file is generated from configure.in by Autoconf.  DO NOT EDIT!
+ # Local configure fragment for sysdeps/unix/sysv/linux/x86_64.
+
+lib_names_awk=sysdeps/unix/sysv/linux/x86_64/lib-names.awk
diff --git a/sysdeps/unix/sysv/linux/x86_64/configure.in b/sysdeps/unix/sysv/linux/x86_64/configure.in
new file mode 100644
index 0000000..8009ee9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/configure.in
@@ -0,0 +1,5 @@
+GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
+# Local configure fragment for sysdeps/unix/sysv/linux/x86_64.
+
+dnl Need to handle lib-names properly for x86-64 and x32.
+lib_names_awk=sysdeps/unix/sysv/linux/x86_64/lib-names.awk
diff --git a/sysdeps/unix/sysv/linux/x86_64/lib-names.awk b/sysdeps/unix/sysv/linux/x86_64/lib-names.awk
new file mode 100644
index 0000000..5a2d0d4
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/lib-names.awk
@@ -0,0 +1,122 @@
+# awk script for soversions.i -> gnu/lib-names.h; see Makeconfig.
+
+$1 != "DEFAULT" { multi = 1 }
+
+#
+{
+  lib = $2;
+  version = $3;
+  if ($3 !~ /^[0-9]/) {
+    soname = $3;
+    extra = $3;
+    sub(/\.so.*$/, "", extra);
+  }
+  else {
+    soname = lib ".so." $3;
+    extra = "";
+  }
+  soname = "\"" soname "\"";
+  lib = toupper(lib);
+  extra = toupper(extra);
+  gsub(/-/, "_", lib);
+  gsub(/-/, "_", extra);
+  if (extra) {
+    if (extra == "LD_LINUX_X32") {
+      x32_macros[$1 FS lib "_SO"] = soname;
+      x32_macros[$1 FS extra "_SO"] = soname;
+      x86_64_macros[$1 FS lib "_SO"] = "\"ld-linux-x86-64.so.2\"";
+      x86_64_macros[$1 FS "LD_LINUX_X86_64_SO"] = "\"ld-linux-x86-64.so.2\"";
+    }
+    else if (extra == "LD_LINUX_X86_64") {
+      x86_64_macros[$1 FS lib "_SO"] = soname;
+      x86_64_macros[$1 FS extra "_SO"] = soname;
+      x32_macros[$1 FS lib "_SO"] = "\"ld-linux-x32.so.2\"";
+      x32_macros[$1 FS "LD_LINUX_X32_SO"] = "\"ld-linux-x32.so.2\"";
+    }
+    else if (extra == "LD_LINUX") {
+      x86_64_macros[$1 FS lib "_SO"] = "\"ld-linux-x86-64.so.2\"";
+      x86_64_macros[$1 FS "LD_LINUX_X86_64_SO"] = "\"ld-linux-x86-64.so.2\"";
+      x32_macros[$1 FS lib "_SO"] = "\"ld-linux-x32.so.2\"";
+      x32_macros[$1 FS "LD_LINUX_X32_SO"] = "\"ld-linux-x32.so.2\"";
+      macros[$1 FS lib "_SO"] = soname;
+      macros[$1 FS extra "_SO"] = soname;
+    }
+    else if (extra != "LD") {
+      macros[$1 FS lib "_SO"] = soname;
+      macros[$1 FS extra "_SO"] = soname;
+    }
+  }
+  else {
+    macros[$1 FS lib "_SO"] = soname;
+  }
+}
+
+END {
+  print "/* This file is automatically generated.";
+  print "   It defines macros to allow user program to find the shared";
+  print "   library files which come as part of GNU libc.  */";
+  print "#ifndef __GNU_LIB_NAMES_H";
+  print "#define __GNU_LIB_NAMES_H	1";
+  print "";
+
+  pfx = multi ? "# define " : "#define ";
+  for (elt in macros) {
+    split(elt, x);
+    line = sprintf("%-40s%s", pfx x[2], macros[elt]);
+    if (x[1] in lines)
+      lines[x[1]] = lines[x[1]] "\n" line;
+    else
+      lines[x[1]] = line;
+  }
+
+  if (multi) {
+    # Print these in a fixed order so the result is identical
+    # on both sides of the coin.
+    pfx = "#  define ";
+    for (elt in x32_macros) {
+      split(elt, x);
+      line = sprintf("%-40s%s", pfx x[2], x32_macros[elt]);
+      if (x[1] in x32_lines)
+	x32_lines[x[1]] = x32_lines[x[1]] "\n" line;
+      else
+	x32_lines[x[1]] = line;
+    }
+    for (elt in x86_64_macros) {
+      split(elt, x);
+      line = sprintf("%-40s%s", pfx x[2], x86_64_macros[elt]);
+      if (x[1] in x86_64_lines)
+	x86_64_lines[x[1]] = x86_64_lines[x[1]] "\n" line;
+      else
+	x86_64_lines[x[1]] = line;
+    }
+    if (!("WORDSIZE32" in lines))
+      lines["WORDSIZE32"] = lines["DEFAULT"];
+    if (!("WORDSIZE64" in lines))
+      lines["WORDSIZE64"] = lines["DEFAULT"];
+    if (!("WORDSIZE32" in x32_lines))
+      x32_lines["WORDSIZE32"] = x32_lines["DEFAULT"];
+    if (!("WORDSIZE64" in x32_lines))
+      x32_lines["WORDSIZE64"] = x32_lines["DEFAULT"];
+    if (!("WORDSIZE32" in x86_64_lines))
+      x86_64_lines["WORDSIZE32"] = x86_64_lines["DEFAULT"];
+    if (!("WORDSIZE64" in x86_64_lines))
+      x86_64_lines["WORDSIZE64"] = x86_64_lines["DEFAULT"];
+    print "#include <bits/wordsize.h>\n";
+    print "#ifndef __x86_64__";
+    cmd = "LC_ALL=C sort"; print lines["WORDSIZE32"] | cmd; close(cmd);
+    print "#else"
+    print "# if __WORDSIZE == 32"
+    cmd = "LC_ALL=C sort"; print x32_lines["WORDSIZE64"] | cmd; close(cmd);
+    print "# else"
+    cmd = "LC_ALL=C sort"; print x86_64_lines["WORDSIZE64"] | cmd; close(cmd);
+    print "# endif"
+    cmd = "LC_ALL=C sort"; print lines["WORDSIZE64"] | cmd; close(cmd);
+    print "#endif";
+  }
+  else {
+    cmd = "LC_ALL=C sort"; print lines["DEFAULT"] | cmd; close(cmd);
+  }
+
+  print "";
+  print "#endif	/* gnu/lib-names.h */"
+}
-- 
1.7.6.5

