about summary refs log tree commit diff
path: root/pkgs/os-specific/linux/minimal-bootstrap
diff options
context:
space:
mode:
authorEmily Trau <emily@downunderctf.com>2023-06-25 15:01:04 +1000
committerEmily Trau <emily@downunderctf.com>2023-06-25 15:01:04 +1000
commit0b6f86e46a0884fd4f5e849c441a0b06c6809ac7 (patch)
tree8e1d5ff082d31886982897711f35f6d1a67f472a /pkgs/os-specific/linux/minimal-bootstrap
parent82dc8d7b7978544f704671f1f526b34fd5d45741 (diff)
downloadnixlib-0b6f86e46a0884fd4f5e849c441a0b06c6809ac7.tar
nixlib-0b6f86e46a0884fd4f5e849c441a0b06c6809ac7.tar.gz
nixlib-0b6f86e46a0884fd4f5e849c441a0b06c6809ac7.tar.bz2
nixlib-0b6f86e46a0884fd4f5e849c441a0b06c6809ac7.tar.lz
nixlib-0b6f86e46a0884fd4f5e849c441a0b06c6809ac7.tar.xz
nixlib-0b6f86e46a0884fd4f5e849c441a0b06c6809ac7.tar.zst
nixlib-0b6f86e46a0884fd4f5e849c441a0b06c6809ac7.zip
minimal-bootstrap.binutils-mes: init at 2.20.1
Diffstat (limited to 'pkgs/os-specific/linux/minimal-bootstrap')
-rw-r--r--pkgs/os-specific/linux/minimal-bootstrap/binutils/default.nix118
-rw-r--r--pkgs/os-specific/linux/minimal-bootstrap/binutils/deterministic.patch12
-rw-r--r--pkgs/os-specific/linux/minimal-bootstrap/default.nix16
3 files changed, 146 insertions, 0 deletions
diff --git a/pkgs/os-specific/linux/minimal-bootstrap/binutils/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/binutils/default.nix
new file mode 100644
index 000000000000..8722ff818297
--- /dev/null
+++ b/pkgs/os-specific/linux/minimal-bootstrap/binutils/default.nix
@@ -0,0 +1,118 @@
+{ lib
+, buildPlatform
+, hostPlatform
+, fetchurl
+, bash
+, gnumake
+, gnupatch
+, gnugrep
+, gnutar
+, gawk
+, bzip2
+, sed
+, mesBootstrap ? false, tinycc ? null
+, gcc ? null, glibc ? null, binutils ? null, linux-headers
+}:
+assert mesBootstrap -> tinycc != null;
+assert !mesBootstrap -> gcc != null && glibc != null && binutils != null;
+let
+  pname = "binutils" + lib.optionalString mesBootstrap "-mes";
+  version = "2.20.1";
+  rev = "a";
+
+  src = fetchurl {
+    url = "mirror://gnu/binutils/binutils-${version}${rev}.tar.bz2";
+    sha256 = "0r7dr0brfpchh5ic0z9r4yxqn4ybzmlh25sbp30cacqk8nb7rlvi";
+  };
+
+  patches = [
+    # Enables building binutils using TCC and Mes C Library
+    (fetchurl {
+      url = "https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/patches/binutils-boot-2.20.1a.patch?id=50249cab3a98839ade2433456fe618acc6f804a5";
+      sha256 = "086sf6an2k56axvs4jlky5n3hs2l3rq8zq5d37h0b69cdyh7igpn";
+    })
+
+    # Make binutils output deterministic by default.
+    ./deterministic.patch
+  ];
+
+  configureFlags = [
+    "--disable-nls"
+    "--disable-shared"
+    "--disable-werror"
+    "--prefix=${placeholder "out"}"
+
+    "--build=${buildPlatform.config}"
+    "--host=${hostPlatform.config}"
+
+    # Turn on --enable-new-dtags by default to make the linker set
+    # RUNPATH instead of RPATH on binaries.  This is important because
+    # RUNPATH can be overridden using LD_LIBRARY_PATH at runtime.
+    "--enable-new-dtags"
+
+    # By default binutils searches $libdir for libraries. This brings in
+    # libbfd and libopcodes into a default visibility. Drop default lib
+    # path to force users to declare their use of these libraries.
+    "--with-lib-path=:"
+  ];
+in
+bash.runCommand "${pname}-${version}" {
+  inherit pname version;
+
+  nativeBuildInputs = [
+    (if mesBootstrap then tinycc.compiler else gcc)
+    gnumake
+    gnupatch
+    gnugrep
+    gnutar
+    gawk
+    bzip2
+    sed
+  ] ++ lib.optional (!mesBootstrap) binutils;
+
+  passthru.tests.get-version = result:
+    bash.runCommand "${pname}-get-version-${version}" {} ''
+      ${result}/bin/ld --version
+      mkdir $out
+    '';
+
+  meta = with lib; {
+    description = "Tools for manipulating binaries (linker, assembler, etc.)";
+    homepage = "https://www.gnu.org/software/binutils";
+    license = licenses.gpl3Plus;
+    maintainers = teams.minimal-bootstrap.members;
+    platforms = platforms.unix;
+  };
+} ''
+  # Unpack
+  cp ${src} binutils.tar.bz2
+  bunzip2 binutils.tar.bz2
+  tar xf binutils.tar
+  rm binutils.tar
+  cd binutils-${version}
+
+  # Patch
+  ${lib.concatMapStringsSep "\n" (f: "patch -Np1 -i ${f}") patches}
+  # Clear the default library search path.
+  echo 'NATIVE_LIB_DIRS=' >> ld/configure.tgt
+
+  # Configure
+  ${if mesBootstrap then ''
+    export CC="tcc -B ${tinycc.libs}/lib -D __GLIBC_MINOR__=6 -D MES_BOOTSTRAP=1"
+    export AR="tcc -ar"
+  '' else ''
+    export CC="gcc -B ${glibc}/lib -I${glibc}/include -I${linux-headers}/include"
+    export CPP="gcc -E -I${glibc}/include -I${linux-headers}/include"
+    export AR="ar"
+    export LIBRARY_PATH="${glibc}/lib"
+    export LIBS="-lc -lnss_files -lnss_dns -lresolv"
+  ''}
+  export SED=sed
+  bash ./configure ${lib.concatStringsSep " " configureFlags}
+
+  # Build
+  make
+
+  # Install
+  make install
+''
diff --git a/pkgs/os-specific/linux/minimal-bootstrap/binutils/deterministic.patch b/pkgs/os-specific/linux/minimal-bootstrap/binutils/deterministic.patch
new file mode 100644
index 000000000000..736e0aca6ce1
--- /dev/null
+++ b/pkgs/os-specific/linux/minimal-bootstrap/binutils/deterministic.patch
@@ -0,0 +1,12 @@
+diff -ur orig/binutils-2.23.1/ld/ldlang.c binutils-2.23.1/ld/ldlang.c
+--- orig/ld/ldlang.c
++++ new/ld/ldlang.c
+@@ -3095,6 +3095,8 @@
+                           ldfile_output_machine))
+     einfo (_("%P%F:%s: can not set architecture: %E\n"), name);
+ 
++  link_info.output_bfd->flags |= BFD_DETERMINISTIC_OUTPUT;
++
+   link_info.hash = bfd_link_hash_table_create (link_info.output_bfd);
+   if (link_info.hash == NULL)
+     einfo (_("%P%F: can not create hash table: %E\n"));
diff --git a/pkgs/os-specific/linux/minimal-bootstrap/default.nix b/pkgs/os-specific/linux/minimal-bootstrap/default.nix
index 2b8763be01ff..1a8dd34bd481 100644
--- a/pkgs/os-specific/linux/minimal-bootstrap/default.nix
+++ b/pkgs/os-specific/linux/minimal-bootstrap/default.nix
@@ -15,6 +15,20 @@ lib.makeScope
 
     bash_2_05 = callPackage ./bash/2.nix { tinycc = tinycc-mes; };
 
+    binutils = callPackage ./binutils {
+      bash = bash_2_05;
+      gcc = gcc2;
+      binutils = binutils-mes;
+      glibc = glibc22;
+      sed = heirloom.sed;
+    };
+    binutils-mes = callPackage ./binutils {
+      bash = bash_2_05;
+      tinycc = tinycc-mes;
+      sed = heirloom.sed;
+      mesBootstrap = true;
+    };
+
     bzip2 = callPackage ./bzip2 {
       bash = bash_2_05;
       tinycc = tinycc-mes;
@@ -82,6 +96,8 @@ lib.makeScope
 
     test = kaem.runCommand "minimal-bootstrap-test" {} ''
       echo ${bash_2_05.tests.get-version}
+      echo ${binutils.tests.get-version}
+      echo ${binutils-mes.tests.get-version}
       echo ${bzip2.tests.get-version}
       echo ${gawk.tests.get-version}
       echo ${gnugrep.tests.get-version}