Skip to content

Debian patches that could be useful #51

@charles2910

Description

@charles2910

Hi,

I'm looking at wcc package in Debian to fix a bug and noticed there are a lot of patches that make sense to upstream (or at least worth discussing if it makes sense). I'll list them here and can prepare a MR with the ones you think are worthy upstreaming.

Make binutiles private shared library staticaly linked
Description: Make binutiles private shared library staticaly linked
 This patch correct Debian bug #949601, makin libbfd staticaly linked
 to wcc and wld.
Author: Philippe Thierry
Last-Update: 2020-01-06
Index: wcc/src/wcc/Makefile
===================================================================
--- wcc.orig/src/wcc/Makefile
+++ wcc/src/wcc/Makefile
@@ -25,8 +25,8 @@
 WCC :=  ./wcc
 FILE := file

-all::
-       $(CC) $(CFLAGS) wcc.c -o wcc -lbfd -lelf -lcapstone
+all:
+       $(CC) $(CFLAGS) wcc.c -o wcc -l:libbfd.a -l:libsframe.a -lz -ldl -liberty -lzstd -lelf -lcapstone
 #      $(CC) $(CFLAGS) -m32 -Wl,-rpath /home/jonathan/solution-exp/unlinking/awareness/self/wcc/src/wcc/lib32/  wcc.c -o wcc32 -lelf ./lib32/libbfd-2.24-system.so ./lib32/libcapstone.so.3

        cp wcc ../../bin/
Index: wcc/src/wld/Makefile
===================================================================
--- wcc.orig/src/wld/Makefile
+++ wcc/src/wld/Makefile
@@ -18,8 +18,8 @@

 CFLAGS := -W -Wall -Wno-discarded-qualifiers -Wno-int-conversion -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -fpie -pie -fPIC -g3 -ggdb -I../../include  -I./include/sflib/ -I./include -I../../include/  -Wno-incompatible-pointer-types  -fstack-protector-all -Wl,-z,relro,-z,now -DPACKAGE -DPACKAGE_VERSION -masm=intel -rdynamic -D_FORTIFY_SOURCE=2 -O2

-all::
-       $(CC) $(CFLAGS) wld.c -o wld -lbfd
+all:
+       $(CC) $(CFLAGS) wld.c -o wld -l:libbfd.a -lz -ldl -liberty
 #      $(CC) $(CFLAGS) wld.c -o wld32 -m32 ../lib32/usr/lib/libbfd.a

        cp wld ../../bin/
Add support for complete Debian hardening
From: Debian Security Tools <team+pkg-security@tracker.debian.org>
Date: Mon, 6 Oct 2025 23:33:28 -0300
Subject: Add support for complete Debian hardening

Support for including complementary CFLAGS from
debian/rules.

Last-Update: 2025-10-06
---
 Makefile          |  6 +++---
 src/wcc/Makefile  |  2 +-
 src/wld/Makefile  |  4 ++--
 src/wldd/Makefile |  4 ++--
 src/wsh/Makefile  | 12 ++++++------
 5 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/Makefile b/Makefile
index 123ad52..df87069 100644
--- a/Makefile
+++ b/Makefile
@@ -14,12 +14,12 @@ else
   ASAN   := -fsanitize=address -static-libasan
 endif

-CFLAGS := -W -Wall -Wno-discarded-qualifiers -Wno-int-conversion -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -fpie -pie -fPIC -g3 -ggdb -I../../include  -I./include/sflib/ -I./include -I../../include/  -Wno-incompatible-pointer-types  -fstack-protector-all -Wl,-z,relro,-z,now -DPACKAGE -DPACKAGE_VERSION -masm=intel -rdynamic -D_FORTIFY_SOURCE=2 -O2
-
+CUSTOM_CFLAGS := -W -Wall -Wno-discarded-qualifiers -Wno-int-conversion -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -fpie -pie -fPIC -g3 -ggdb -I../../include  -I./include/sflib/ -I./include -I../../include/  -Wno-incompatible-pointer-types  -fstack-protector-all -Wl,-z,relro,-z,now -DPACKAGE -DPACKAGE_VERSION -masm=intel -rdynamic -D_FORTIFY_SOURCE=2 -O2
+CUSTOM_CFLAGS += $(CFLAGS)

 all:
        mkdir -p bin
-       cd src && make CFLAGS=" $(CFLAGS)"
+       cd src && make CFLAGS=" $(CUSTOM_CFLAGS)"

 asan: CFLAGS += $(ASAN)
 asan: all
diff --git a/src/wcc/Makefile b/src/wcc/Makefile
index 4489b4d..524f947 100644
--- a/src/wcc/Makefile
+++ b/src/wcc/Makefile
@@ -26,7 +26,7 @@ WCC :=  ./wcc
 FILE := file

 all:
-       $(CC) $(CFLAGS) wcc.c -o wcc -l:libbfd.a -l:libsframe.a -lz -ldl -liberty -lzstd -lelf -lcapstone
+       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) wcc.c -o wcc -l:libbfd.a -l:libsframe.a -lz -ldl -liberty -lzstd -lelf -lcapstone
 #      $(CC) $(CFLAGS) -m32 -Wl,-rpath /home/jonathan/solution-exp/unlinking/awareness/self/wcc/src/wcc/lib32/  wcc.c -o wcc32 -lelf ./lib32/libbfd-2.24-system.so ./lib32/libcapstone.so.3

        cp wcc ../../bin/
diff --git a/src/wld/Makefile b/src/wld/Makefile
index e9fbf84..3283dc9 100644
--- a/src/wld/Makefile
+++ b/src/wld/Makefile
@@ -16,10 +16,10 @@
 # any ELF (from any architecture/OS/endianness).
 #

-CFLAGS := -W -Wall -Wno-discarded-qualifiers -Wno-int-conversion -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -fpie -pie -fPIC -g3 -ggdb -I../../include  -I./include/sflib/ -I./include -I../../include/  -Wno-incompatible-pointer-types  -fstack-protector-all -Wl,-z,relro,-z,now -DPACKAGE -DPACKAGE_VERSION -masm=intel -rdynamic -D_FORTIFY_SOURCE=2 -O2
+CFLAGS ?= -W -Wall -Wno-discarded-qualifiers -Wno-int-conversion -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -fpie -pie -fPIC -g3 -ggdb -I../../include  -I./include/sflib/ -I./include -I../../include/  -Wno-incompatible-pointer-types  -fstack-protector-all -Wl,-z,relro,-z,now -DPACKAGE -DPACKAGE_VERSION -masm=intel -rdynamic -D_FORTIFY_SOURCE=2 -O2

 all:
-       $(CC) $(CFLAGS) wld.c -o wld -l:libbfd.a -lz -ldl -liberty
+       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) wld.c -o wld -l:libbfd.a -lz -ldl -liberty
 #      $(CC) $(CFLAGS) wld.c -o wld32 -m32 ../lib32/usr/lib/libbfd.a

        cp wld ../../bin/
diff --git a/src/wldd/Makefile b/src/wldd/Makefile
index de7b157..e9d9d8e 100644
--- a/src/wldd/Makefile
+++ b/src/wldd/Makefile
@@ -1,7 +1,7 @@
-CFLAGS := -W -Wall
+CFLAGS ?= -W -Wall

 all::
-       $(CC) $(CFLAGS) wldd.c -o wldd -lelf
+       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) wldd.c -o wldd -lelf
        cp wldd ../../bin/

 clean:
diff --git a/src/wsh/Makefile b/src/wsh/Makefile
index d06da1a..da24547 100644
--- a/src/wsh/Makefile
+++ b/src/wsh/Makefile
@@ -16,13 +16,13 @@ LUA_LINK_FLAGS := $(shell pkg-config lua5.3 --libs)
 CFLAGS += $(LUA_CFLAGS)

 all::
-       $(CC) $(CFLAGS) wsh.c -o wsh.o -c -fpie -fPIC -ldl -lreadline
-       $(CC) $(CFLAGS) wshmain.c -o wshmain.o -c -fpie -fPIC -ldl -lreadline
-       $(CC) $(CFLAGS) helper.c -o helper.o -c -fpie -fPIC
-       $(CC) $(CFLAGS) linenoise/linenoise.c -o linenoise.o -c -fpie -fPIC
-       $(CC) $(CFLAGS) wsh.o helper.o linenoise.o -shared -fPIC -o libwitch.so
+       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) wsh.c -o wsh.o -c -fpie -fPIC -ldl -lreadline
+       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) wshmain.c -o wshmain.o -c -fpie -fPIC -ldl -lreadline
+       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) helper.c -o helper.o -c -fpie -fPIC
+       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) linenoise/linenoise.c -o linenoise.o -c -fpie -fPIC
+       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) wsh.o helper.o linenoise.o -shared -fPIC -o libwitch.so
        ar cr libwitch.a wsh.o helper.o linenoise.o
-       $(CC) $(CFLAGS) wsh.o helper.o linenoise.o wshmain.o -o wsh -Wl,-T -Wl,script.lds -liberty -lm -ldl $(LUA_LINK_FLAGS)
+       $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) wsh.o helper.o linenoise.o wshmain.o -o wsh -Wl,-T -Wl,script.lds -liberty -lm -ldl $(LUA_LINK_FLAGS)

        cp wsh ../../bin/
Update doxygen header file to compile
Description: Update doxygen header file to compile
 This patch correct a bug in doxygen when using custom header
 including '\+' char in various places in the generated LaTeX
 files. This patch declare the '\+' LaTeX command as an empty
 command to avoid compilation failure.
Author: Philippe Thierry
Last-Update: 2017-04-28
Index: wcc/src/tex/header.tex
===================================================================
--- wcc.orig/src/tex/header.tex
+++ wcc/src/tex/header.tex
@@ -106,6 +106,9 @@
   \newpage{\pagestyle{empty}\cleardoublepage}%
 }

+% correcting doxygen bug due to custom header
+\newcommand{\+}{}
+

 %===== C O N T E N T S =====
Add support for kernels others than Linux
Description: Add support for kernels others than Linux
 This support embedded a local implementation of elf-em.h.
 This file simply defines a list of constants specifying target arch for ELF
 binary. The constant name is specific to this file and Linux-specific.
Bug-Debian: https://bugs.debian.org/873783
Author: Philippe Thierry
Last-Update: 2017-08-31
--- a/include/arch.h
+++ b/include/arch.h
@@ -29,7 +29,14 @@
 *
 */

-#include <linux/elf-em.h>
+/* supporting elf-em with other kernels (only constants definitions) */
+#ifdef __FreeBSD_kernel__
+  #include "elf-em.h"
+#elif defined __GNU__
+  #include "elf-em.h"
+#else
+  #include <linux/elf-em.h>
+#endif

 typedef struct archi_t{
        char *name;
--- /dev/null
+++ b/include/elf-em.h
@@ -0,0 +1,59 @@
+#ifndef _LINUX_ELF_EM_H
+#define _LINUX_ELF_EM_H
+
+/* These constants define the various ELF target machines */
+#define EM_NONE                0
+#define EM_M32         1
+#define EM_SPARC       2
+#define EM_386         3
+#define EM_68K         4
+#define EM_88K         5
+#define EM_486         6       /* Perhaps disused */
+#define EM_860         7
+#define EM_MIPS                8       /* MIPS R3000 (officially, big-endian only) */
+                               /* Next two are historical and binaries and
+                                **                                modules of
+                                **                                these types
+                                **                                will be
+                                **                                rejected by
+                                **                                                                Linux.
+                                **                                                                */
+#define EM_MIPS_RS3_LE 10      /* MIPS R3000 little-endian */
+#define EM_MIPS_RS4_BE 10      /* MIPS R4000 big-endian */
+
+#define EM_PARISC      15      /* HPPA */
+#define EM_SPARC32PLUS 18      /* Sun's "v8plus" */
+#define EM_PPC         20      /* PowerPC */
+#define EM_PPC64       21       /* PowerPC64 */
+#define EM_SPU         23      /* Cell BE SPU */
+#define EM_SH          42      /* SuperH */
+#define EM_SPARCV9     43      /* SPARC v9 64-bit */
+#define EM_IA_64       50      /* HP/Intel IA-64 */
+#define EM_X86_64      62      /* AMD x86-64 */
+#define EM_S390                22      /* IBM S/390 */
+#define EM_CRIS                76      /* Axis Communications 32-bit embedded processor */
+#define EM_V850                87      /* NEC v850 */
+#define EM_M32R                88      /* Renesas M32R */
+#define EM_H8_300      46      /* Renesas H8/300,300H,H8S */
+#define EM_MN10300     89      /* Panasonic/MEI MN10300, AM33 */
+#define EM_BLACKFIN     106     /* ADI Blackfin Processor */
+#define EM_FRV         0x5441  /* Fujitsu FR-V */
+#define EM_AVR32       0x18ad  /* Atmel AVR32 */
+
+/*
+**  * This is an interim value that we will use until the committee comes
+**   * up with a final number.
+**    */
+#define EM_ALPHA       0x9026
+
+/* Bogus old v850 magic number, used by old tools. */
+#define EM_CYGNUS_V850 0x9080
+/* Bogus old m32r magic number, used by old tools. */
+#define EM_CYGNUS_M32R 0x9041
+/* This is the old interim value for S/390 architecture */
+#define EM_S390_OLD    0xA390
+/* Also Panasonic/MEI MN10300, AM33 */
+#define EM_CYGNUS_MN10300 0xbeef
+
+
+#endif /* _LINUX_ELF_EM_H */
Remove compilation time timestamping in binary
From: Debian Security Tools <team+pkg-security@tracker.debian.org>
Date: Mon, 6 Oct 2025 23:33:28 -0300
Subject: Remove compilation time timestamping in binaries

This patch make the binaries reproducible by deleting the usage of
WTIME and WDATE in the binaries version.

Last-Update: 2025-10-06
---
 src/wcc/wcc.c | 2 +-
 src/wld/wld.c | 2 +-
 src/wsh/wsh.c | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/wcc/wcc.c b/src/wcc/wcc.c
index 709c962..1c84fa0 100644
--- a/src/wcc/wcc.c
+++ b/src/wcc/wcc.c
@@ -3729,7 +3729,7 @@ int usage(char *name)

 int print_version(void)
 {
-  printf("%s version:%s    (%s %s)\n", WNAME, WVERSION, WTIME, WDATE);
+  printf("%s version:%s\n", WNAME, WVERSION);
   return 0;
 }

diff --git a/src/wld/wld.c b/src/wld/wld.c
index 4cb0826..26cc36e 100644
--- a/src/wld/wld.c
+++ b/src/wld/wld.c
@@ -176,7 +176,7 @@ int mk_lib(char *name, unsigned int noinit)

 int print_version(void)
 {
-  printf("%s version:%s    (%s %s)\n", WNAME, WVERSION, WTIME, WDATE);
+  printf("%s version:%s\n", WNAME, WVERSION);
   return 0;
 }

diff --git a/src/wsh/wsh.c b/src/wsh/wsh.c
index 7bc608c..f92ec79 100644
--- a/src/wsh/wsh.c
+++ b/src/wsh/wsh.c
@@ -910,7 +910,7 @@ int headers(lua_State * L)

        read_arg1(libname);

-       printf("/**\n*\n* Automatically generated by the Witchcraft Compiler Collection %s\n*\n* %s %s\n*\n*/\n\n\n", WVERSION, WTIME, WDATE);
+       printf("/**\n*\n* Automatically generated by the Witchcraft Compiler Collection %s\n\n\n", WVERSION);

        /**
        * generate headers for imported objects
@@ -5464,7 +5464,7 @@ nomoreargs:
 */
 int wsh_print_version(void)
 {
-       printf("%s version:%s    (%s %s)\n", WNAME, WVERSION, WTIME, WDATE);
+       printf("%s version:%s\n", WNAME, WVERSION);
        return 0;
 }

Updated scripts shebang
Description: Updated scripts shebang
 Updated wsh script to use proper shebang corresponding
 to WCC installation.
Author: Philippe Thierry
Last-Update: 2017-05-24
Index: wcc/src/wsh/scripts/main.wsh
===================================================================
--- wcc.orig/src/wsh/scripts/main.wsh
+++ wcc/src/wsh/scripts/main.wsh
@@ -1,3 +1,5 @@
+#!/usr/bin/wsh
+
 local ffi = require("ffi")
 ffi.cdef[[
 unsigned long compressBound(unsigned long sourceLen);
spelling corrections in man pages
Description: spelling corrections in man pages
 Various spelling corrections after spellintian pass
 on man pages.
Author: Philippe Thierry
Last-Update: 2017-05-23
Index: wcc/doc/manpages/wld.1
===================================================================
--- wcc.orig/doc/manpages/wld.1
+++ wcc/doc/manpages/wld.1
@@ -1,6 +1,6 @@
 .TH WLD "1" "April 2017" "Witchcraft Compiler Collection" "User Commands"
 .SH NAME
-wld \- transform executables into shared libaries
+wld \- transform executables into shared libraries
 .SH SYNOPSIS
 .B wld
 \fI-libify\fR [\fI-noinit\fR] \fIfile\fR
Correct various spelling error in sources
Description: Correct various spelling error in sources
 This patch correct spelling error detected by spellintian
 in the binary files.
Author: Philippe Thierry
Last-Update: 2017-04-28
Index: wcc/src/wcc/wcc.c
===================================================================
--- wcc.orig/src/wcc/wcc.c
+++ wcc/src/wcc/wcc.c
@@ -1235,7 +1235,7 @@ static unsigned int write_phdrs(ctx_t *
   ctx->phnum += 2;

   if (ctx->opt_verbose) {
-    printf(" -- Writting %u segment headers\n", ctx->phnum);
+    printf(" -- Writing %u segment headers\n", ctx->phnum);
   }
   // first entry is the program header itself
   Elf_Phdr *phdr = calloc(1, sizeof(Elf_Phdr));
Index: wcc/src/wsh/include/libwitch/wsh_help.h
===================================================================
--- wcc.orig/src/wsh/include/libwitch/wsh_help.h
+++ wcc/src/wsh/include/libwitch/wsh_help.h
@@ -56,7 +56,7 @@ help_t cmdhelp[] ={
 * Internal help : wsh functions
 */
 help_t fcnhelp[] ={
-       {"help", "[topic]","Display help on [topic]. If [topic] is ommitted, display general help.", "",
"None"},
+       {"help", "[topic]","Display help on [topic]. If [topic] is omitted, display general help.", "", "
None"},
        {"man", "[page]", "Display system manual page for [page].", "", "None"},
        {"hexdump", "<address>, <num>", "Display <num> bytes from memory <address> in enhanced hexadecimal form.", "", "None"},
        {"hex", "<object>", "Display lua <object> in enhanced hexadecimal form.", "", "None"},
@@ -68,7 +68,7 @@ help_t fcnhelp[] ={
        {"symbols", "[sympattern], [libpattern], [mode]", "Display all the symbols in memory matching [sympattern], from library [libpattern]. If [mode] is set to 1 or 2, do not wait user input between pagers. [mode] = 2 provides a shorter output.", "", "None"},
        {"functions","[sympattern], [libpattern], [mode]", "Display all the functions in memory matching [sympattern], from library [libpattern]. If [mode] is set to 1 or 2, do not wait user input between pagers. [mode] = 2 provides a shorter output.", "table func = ", "Return 1 lua table _func_ whose keys are valid function names in address space, and values are pointers to them in memory."},
        {"objects","[pattern]", "Display all the functions in memory matching [sympattern]", "", "None"},
-       {"info", "[address] | [name]", "Display various informations about the [address] or [name] provided : if it is mapped, and if so from which library and in which section if available.", "", "None"},
+       {"info", "[address] | [name]", "Display various information about the [address] or [name] provided : if it is mapped, and if so from which library and in which section if available.", "", "None"},
        {"search", "<pattern>", "Search all object names matching <pattern> in address space.", "", "None"},
        {"headers", "", "Display C headers suitable for linking against the API loaded in address space.", "", "None"},
        {"grep", "<pattern>, [patternlen], [dumplen], [before]","Search <pattern> in all ELF sections in
memory. Match [patternlen] bytes, then display [dumplen] bytes, optionally including [before] bytes befor
e the match. Results are displayed in enhanced decimal form", "table match = ", "Returns 1 lua table cont
aining matching memory addresses."},
Index: wcc/src/wsh/wsh.c
===================================================================
--- wcc.orig/src/wsh/wsh.c
+++ wcc/src/wsh/wsh.c
@@ -556,7 +556,7 @@ int help(lua_State * L)
                printf(" + memory maps:\n\tshdrs(), phdrs(), map(), procmap(), bfmap()\n\n");
                printf(" + symbols:\n\tsymbols(), functions(), objects(), info(), search(), headers()\n\n
");
                printf(" + memory search:\n\tgrep(), grepptr()\n\n");
-               printf(" + load libaries:\n\tloadbin(), libs(), entrypoints(), rescan()\n\n");
+               printf(" + load libraries:\n\tloadbin(), libs(), entrypoints(), rescan()\n\n");
                printf(" + code execution:\n\tlibcall()\n\n");
                printf(" + buffer manipulation:\n\txalloc(), ralloc(), xfree(), balloc(), bset(), bget(),
 rdstr(), rdnum()\n\n");
                printf(" + control flow:\n\t breakpoint(), bp()\n\n");
@@ -2083,7 +2083,7 @@ int prototypes(lua_State * L)
        */
        HASH_SRT(hh, protorecords, sort_learnt);

-       printf("\n [*] Prototypes: (from %u tag informations)\n", HASH_COUNT(protorecords));
+       printf("\n [*] Prototypes: (from %u tag information)\n", HASH_COUNT(protorecords));
        HASH_ITER(hh, protorecords, l, p) {
                if((!patternlib) || (strstr(l->key.tlib, patternlib))){
                        if((!pattern) || (!strncmp(pattern, l->key.tfunction, strlen(pattern)))){

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions