dslm4515 / CMLFS

Clang-Built Musl Linux From Scratch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[patch] Build `Libelf from Elfutils` with Clang under musl

owl4ce opened this issue · comments

After so many days of searching .. I finally found it.

elfutils-musl-clang.patch

diff --git a/configure.ac b/configure.ac
index ad046bc2..32524e8a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -105,29 +105,6 @@ AC_CHECK_TOOL([NM], [nm])
 # https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html
 # Arrays of Variable Length
 # https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html
-AC_CACHE_CHECK([for gcc with GNU99 support], ac_cv_c99, [dnl
-old_CFLAGS="$CFLAGS"
-CFLAGS="$CFLAGS -std=gnu99"
-AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl
-int foo (int a)
-{
-  for (int i = 0; i < a; ++i) if (i % 4) break; int s = a; return s;
-}
-
-double bar (double a, double b)
-{
-  double square (double z) { return z * z; }
-  return square (a) + square (b);
-}
-
-void baz (int n)
-{
-  struct S { int x[[n]]; };
-}])],
-		  ac_cv_c99=yes, ac_cv_c99=no)
-CFLAGS="$old_CFLAGS"])
-AS_IF([test "x$ac_cv_c99" != xyes],
-      AC_MSG_ERROR([gcc with GNU99 support required]))
 
 AC_CACHE_CHECK([whether gcc supports __attribute__((visibility()))],
 	ac_cv_visibility, [dnl
diff --git a/src/elfcompress.c b/src/elfcompress.c
index c5ba6c34..96518a32 100644
--- a/src/elfcompress.c
+++ b/src/elfcompress.c
@@ -37,6 +37,10 @@
 #include "libeu.h"
 #include "printversion.h"
 
+#ifndef FNM_EXTMATCH
+# define FNM_EXTMATCH   (1 << 5)        /* Use ksh-like extended matching. */
+#endif
+
 /* Name and version of program.  */
 ARGP_PROGRAM_VERSION_HOOK_DEF = print_version;
 
diff --git a/src/readelf.c b/src/readelf.c
index b9740455..26aac82f 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -8763,12 +8763,12 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
       /* Apply the "operation advance" from a special opcode
 	 or DW_LNS_advance_pc (as per DWARF4 6.2.5.1).  */
       unsigned int op_addr_advance;
-      inline void advance_pc (unsigned int op_advance)
-      {
-	op_addr_advance = minimum_instr_len * ((op_index + op_advance)
-					       / max_ops_per_instr);
-	address += op_addr_advance;
-	op_index = (op_index + op_advance) % max_ops_per_instr;
+#define advance_pc(op_advance) \
+      {\
+	op_addr_advance = minimum_instr_len * ((op_index + op_advance)\
+					       / max_ops_per_instr);\
+	address += op_addr_advance;\
+	op_index = (op_index + op_advance) % max_ops_per_instr;\
       }
 
       if (max_ops_per_instr == 0)
diff --git a/src/strip.c b/src/strip.c
index 7a5d4e4c..f10775d0 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -46,6 +46,10 @@
 #include <system.h>
 #include <printversion.h>
 
+#ifndef FNM_EXTMATCH
+# define FNM_EXTMATCH	(1 << 5)	/* Use ksh-like extended matching. */
+#endif
+
 typedef uint8_t GElf_Byte;
 
 /* Name and version of program.  */

Apply above patch before autoreconf step, then the magic appears.

Ah, I forgot..

Change the configure step into these.
Because the linker (lld) will error if the stack size is applied to CFLAGS, it should be at CXXFLAGS.

CFLAGS="-Wno-error -Wno-null-dereference -DFNM_EXTMATCH=0" \
CXXFLAGS="-Wno-error -Wl,-z,stack-size=2097152" \
./configure --prefix=/usr \
            --disable-debuginfod \
            --disable-libdebuginfod

I am currently doing another build of CMLFS to check for typo's and mistakes before i create the 2.0.0 tag and release... just in time, as I can try this patch as soon as i finish llvmtools.

Also, I corrected this.

I built with clang but failed, should have implemented -D_GNU_SOURCE.

make CC=clang CCOPTS="-D_GNU_SOURCE"

Also, I corrected this.

I built with clang but failed, should have implemented -D_GNU_SOURCE.

make CC=clang CCOPTS="-D_GNU_SOURCE"

Commit 822d0f6

I am currently doing another build of CMLFS to check for typo's and mistakes before i create the 2.0.0 tag and release... just in time, as I can try this patch as soon as i finish llvmtools.

Using LLVM-12.0.1 is fine, but the bug with lld (mach-o) which requires the libunwind header is still there. 😕

I did include scripts to switch between LLVM and GCC+Binutils and LLVM+Binutils for both llvmtools and the final system.

Since libelf can be 'clang-built' ... then the only purpose of GCC in llvmtools is to build GCC for the final system, if I remember correctly.

I still havent found a way to clang-build GRUB without corrupted images (diskboot.img & boot.img)

I did include scripts to switch between LLVM and GCC+Binutils and LLVM+Binutils for both llvmtools and the final system.

Since libelf can be 'clang-built' ... then the only purpose of GCC in llvmtools is to build GCC for the final system, if I remember correctly.

I still havent found a way to clang-build GRUB without corrupted images (diskboot.img & boot.img)

Yeah, but I don't use GRUB btw 😄

Yeah, but I don't use GRUB btw smile

I usually use rEFInd to boot my UEFI laptop, but I couldn't get rEFInd to boot my UEFI Desktop PC. ... If building on ARM64, then likely not grub, lol

Updated libelf build.

commit 5a0c01b

Confirmed patch worked. Cleaning up build: 845b946