Skip to content

Commit

Permalink
glibc: add package (spack#39695)
Browse files Browse the repository at this point in the history
  • Loading branch information
haampie authored Sep 4, 2023
1 parent d367b42 commit 29aa711
Show file tree
Hide file tree
Showing 10 changed files with 426 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lib/spack/spack/util/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,47 @@ def get_rpaths(path):
return rpath.split(":")


def delete_rpath(path):
"""Modifies a binary to remove the rpath. It zeros out the rpath string
and also drops the DT_R(UN)PATH entry from the dynamic section, so it doesn't
show up in 'readelf -d file', nor in 'strings file'."""
with open(path, "rb+") as f:
elf = parse_elf(f, interpreter=False, dynamic_section=True)

if not elf.has_rpath:
return

# Zero out the rpath *string* in the binary
new_rpath_string = b"\x00" * len(elf.dt_rpath_str)
rpath_offset = elf.pt_dynamic_strtab_offset + elf.rpath_strtab_offset
f.seek(rpath_offset)
f.write(new_rpath_string)

# Next update the dynamic array
f.seek(elf.pt_dynamic_p_offset)
dynamic_array_fmt = elf.byte_order + ("qQ" if elf.is_64_bit else "lL")
dynamic_array_size = calcsize(dynamic_array_fmt)
new_offset = elf.pt_dynamic_p_offset # points to the new dynamic array
old_offset = elf.pt_dynamic_p_offset # points to the current dynamic array
for _ in range(elf.pt_dynamic_p_filesz // dynamic_array_size):
data = read_exactly(f, dynamic_array_size, "Malformed dynamic array entry")
tag, _ = unpack(dynamic_array_fmt, data)

# Overwrite any entry that is not DT_RPATH or DT_RUNPATH, including DT_NULL
if tag != ELF_CONSTANTS.DT_RPATH and tag != ELF_CONSTANTS.DT_RUNPATH:
if new_offset != old_offset:
f.seek(new_offset)
f.write(data)
f.seek(old_offset + dynamic_array_size)
new_offset += dynamic_array_size

# End of the dynamic array
if tag == ELF_CONSTANTS.DT_NULL:
break

old_offset += dynamic_array_size


def replace_rpath_in_place_or_raise(path, substitutions):
regex = re.compile(b"|".join(re.escape(p) for p in substitutions.keys()))

Expand Down
21 changes: 21 additions & 0 deletions var/spack/repos/builtin/packages/glibc/32cf406.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
From 32cf40699346d37fabfa887bbd95e95004799ae1 Mon Sep 17 00:00:00 2001
From: Andreas Schwab <[email protected]>
Date: Mon, 6 Sep 2010 14:55:59 +0200
Subject: [PATCH] Don't mix pattern rules with normal rules

diff --git a/manual/Makefile b/manual/Makefile
index c5866eb9def..b1f5fa73e5e 100644
--- a/manual/Makefile
+++ b/manual/Makefile
@@ -232,7 +232,10 @@ ifdef objpfx
.PHONY: stubs
stubs: $(objpfx)stubs
endif
-$(objpfx)stubs ../po/manual.pot $(objpfx)stamp%:
+$(objpfx)stubs ../po/manual.pot:
+ $(make-target-directory)
+ touch $@
+$(objpfx)stamp%:
$(make-target-directory)
touch $@

13 changes: 13 additions & 0 deletions var/spack/repos/builtin/packages/glibc/39b1f61.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/malloc/obstack.c b/malloc/obstack.c
index 25a90514f78..c3c7db4a96b 100644
--- a/malloc/obstack.c
+++ b/malloc/obstack.c
@@ -115,7 +115,7 @@ int obstack_exit_failure = EXIT_FAILURE;
/* A looong time ago (before 1994, anyway; we're not sure) this global variable
was used by non-GNU-C macros to avoid multiple evaluation. The GNU C
library still exports it because somebody might use it. */
-struct obstack *_obstack_compat;
+struct obstack *_obstack_compat = 0;
compat_symbol (libc, _obstack_compat, _obstack, GLIBC_2_0);
# endif
# endif
123 changes: 123 additions & 0 deletions var/spack/repos/builtin/packages/glibc/4a531bb.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
commit 4a531bb0b3b582cb693de9f76d2d97d970f9a5d5
Author: H.J. Lu <[email protected]>
Date: Fri Dec 24 20:14:37 2010 -0500

Remove `.ctors' and `.dtors' output sections

diff --git a/config.h.in b/config.h.in
index 18bf01a38c..9e797eb5b7 100644
--- a/config.h.in
+++ b/config.h.in
@@ -201,6 +201,9 @@
/* Define if multi-arch DSOs should be generated. */
#undef USE_MULTIARCH

+/* Define if `.ctors' and `.dtors' sections shouldn't be used. */
+#define NO_CTORS_DTORS_SECTIONS
+
/*
^L */

diff --git a/elf/sofini.c b/elf/sofini.c
index 5e06f0ca92..13e74b7903 100644
--- a/elf/sofini.c
+++ b/elf/sofini.c
@@ -1,12 +1,14 @@
/* Finalizer module for ELF shared C library. This provides terminating
null pointer words in the `.ctors' and `.dtors' sections. */

+#ifndef NO_CTORS_DTORS_SECTIONS
static void (*const __CTOR_END__[1]) (void)
__attribute__ ((used, section (".ctors")))
= { 0 };
static void (*const __DTOR_END__[1]) (void)
__attribute__ ((used, section (".dtors")))
= { 0 };
+#endif

/* Terminate the frame unwind info section with a 4byte 0 as a sentinel;
this would be the 'length' field in a real FDE. */
diff --git a/elf/soinit.c b/elf/soinit.c
index 6fecbb5674..1db676af01 100644
--- a/elf/soinit.c
+++ b/elf/soinit.c
@@ -3,6 +3,7 @@
the `.ctors' and `.dtors' sections so the lists are terminated, and
calling those lists of functions. */

+#ifndef NO_CTORS_DTORS_SECTIONS
#include <libc-internal.h>
#include <stdlib.h>

@@ -40,3 +41,4 @@ __libc_fini (void)

void (*_fini_ptr) (void) __attribute__ ((section (".fini_array")))
= &__libc_fini;
+#endif
diff --git a/sysdeps/i386/init-first.c b/sysdeps/i386/init-first.c
index c6355a8b7b..2af042fe4b 100644
--- a/sysdeps/i386/init-first.c
+++ b/sysdeps/i386/init-first.c
@@ -59,7 +59,9 @@ _init (int argc, ...)
{
init (&argc);

+#ifndef NO_CTORS_DTORS_SECTIONS
__libc_global_ctors ();
+#endif
}
#endif

diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
index f9a7a58deb..60823bd789 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/i386/init-first.c
@@ -92,7 +92,7 @@ posixland_init (int argc, char **argv, char **envp)
__getopt_clean_environment (envp);
#endif

-#ifdef SHARED
+#if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
__libc_global_ctors ();
#endif
}
diff --git a/sysdeps/mach/hurd/powerpc/init-first.c b/sysdeps/mach/hurd/powerpc/init-first.c
index 20fa1d4f12..21b5054b0a 100644
--- a/sysdeps/mach/hurd/powerpc/init-first.c
+++ b/sysdeps/mach/hurd/powerpc/init-first.c
@@ -82,7 +82,7 @@ posixland_init (int argc, char **argv, char **envp)
__getopt_clean_environment (__environ);
#endif

-#ifdef SHARED
+#if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
__libc_global_ctors ();
#endif
}
diff --git a/sysdeps/sh/init-first.c b/sysdeps/sh/init-first.c
index d816625ef4..1f3a821fea 100644
--- a/sysdeps/sh/init-first.c
+++ b/sysdeps/sh/init-first.c
@@ -59,7 +59,9 @@ _init (int argc, ...)
{
init (&argc);

+#ifndef NO_CTORS_DTORS_SECTIONS
__libc_global_ctors ();
+#endif
}
#endif

diff --git a/sysdeps/unix/sysv/linux/init-first.c b/sysdeps/unix/sysv/linux/init-first.c
index 7b2333d4bf..a60212f4ed 100644
--- a/sysdeps/unix/sysv/linux/init-first.c
+++ b/sysdeps/unix/sysv/linux/init-first.c
@@ -93,7 +93,7 @@ _init (int argc, char **argv, char **envp)
__getopt_clean_environment (envp);
#endif

-#ifdef SHARED
+#if defined SHARED && !defined NO_CTORS_DTORS_SECTIONS
__libc_global_ctors ();
#endif
}
21 changes: 21 additions & 0 deletions var/spack/repos/builtin/packages/glibc/7c8a673.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
commit 7c8a67320e26b8c11108bf0a3410d3aef9cf3486
Author: Ulrich Drepper <[email protected]>
Date: Sat Jan 31 00:21:15 2009 +0000

* elf/Makefile (ld.so): Adjust the sed script to insert _begin in to

newer linker scripts.

diff --git a/elf/Makefile b/elf/Makefile
index 8079fe9f96..e44ff1d382 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -304,7 +304,7 @@ $(objpfx)ld.so: $(objpfx)librtld.os $(ld-map)
$(LDFLAGS-rtld) -Wl,-z,defs -Wl,--verbose 2>&1 | \
LC_ALL=C \
sed -e '/^=========/,/^=========/!d;/^=========/d' \
- -e 's/\. = 0 + SIZEOF_HEADERS;/& _begin = . - SIZEOF_HEADERS;/' \
+ -e 's/\. = .* + SIZEOF_HEADERS;/& _begin = . - SIZEOF_HEADERS;/' \
> [email protected]
$(LINK.o) -nostdlib -nostartfiles -shared -o $@ \
$(LDFLAGS-rtld) -Wl,-z,defs $(z-now-$(bind-now)) \
13 changes: 13 additions & 0 deletions var/spack/repos/builtin/packages/glibc/fb21f89.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/sunrpc/rpc_clntout.c b/sunrpc/rpc_clntout.c
index ec040c775e2..ce4d2a4c953 100644
--- a/sunrpc/rpc_clntout.c
+++ b/sunrpc/rpc_clntout.c
@@ -31,7 +31,7 @@
*/
#include <stdio.h>
#include <string.h>
-#include <rpc/types.h>
+#include "rpc/types.h"
#include "rpc_parse.h"
#include "rpc_util.h"
#include "proto.h"
19 changes: 19 additions & 0 deletions var/spack/repos/builtin/packages/glibc/locs-2.22.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/misc/regexp.c b/misc/regexp.c
index ee7d572..e0b4b47 100644
--- a/misc/regexp.c
+++ b/misc/regexp.c
@@ -23,11 +23,11 @@
#include <regex.h>

/* Define the variables used for the interface. */
-char *loc1;
-char *loc2;
+char *loc1 __attribute__ ((nocommon));
+char *loc2 __attribute__ ((nocommon));

/* Although we do not support the use we define this variable as well. */
-char *locs;
+char *locs __attribute__ ((nocommon));


/* Find the next match in STRING. The compiled regular expression is
20 changes: 20 additions & 0 deletions var/spack/repos/builtin/packages/glibc/locs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- a/misc/regexp.c
+++ b/misc/regexp.c
@@ -29,14 +29,15 @@

#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_23)

-/* Define the variables used for the interface. */
-char *loc1;
-char *loc2;
+/* Define the variables used for the interface. Avoid .symver on common
+ symbol, which just creates a new common symbol, not an alias. */
+char *loc1 __attribute__ ((nocommon));
+char *loc2 __attribute__ ((nocommon));
compat_symbol (libc, loc1, loc1, GLIBC_2_0);
compat_symbol (libc, loc2, loc2, GLIBC_2_0);

/* Although we do not support the use we define this variable as well. */
-char *locs;
+char *locs __attribute__ ((nocommon));
compat_symbol (libc, locs, locs, GLIBC_2_0);
Loading

0 comments on commit 29aa711

Please sign in to comment.