]> git.kaiwu.me - haproxy.git/commitdiff
BUILD: Hopefully fix build on FreeBSD
authorOlivier Houchard <ohouchard@haproxy.com>
Fri, 2 Oct 2026 15:24:20 +0000 (17:24 +0200)
committerOlivier Houchard <cognet@ci0.org>
Fri, 2 Oct 2026 15:24:34 +0000 (17:24 +0200)
Commit 005038b80d468cdca0a9fdcb4b3c993ec02f8367 introduced a new script,
to inject the gnu_debugdata section into the binary. However, the script
used %b to print binary values, and %b behaves differently on Linux and
FreeBSD shells, and on FreeBSD, it would end up corrupting the binary,
making it crash on start.
Fix that by avoid using %b at all.

scripts/minidbg.sh

index bcb369e88678f4a76cabfd1b616251cd60dcfbe4..a3a732bb3d8480a7d881c060dbe15103604d12be 100755 (executable)
@@ -103,14 +103,15 @@ off=$(( (elflen + PAGE - 1) / PAGE * PAGE ))
 vaddr=$(( (maxva + PAGE - 1) / PAGE * PAGE ))
 
 # writes <size> bytes of <value> at <offset>, in the file's byte order
+# Use escapes in the format: BSD printf's %b truncates at NUL bytes.
 wr() {
        _o=$1; _s=$2; _v=$3; _i=0; _e=''
        while [ $_i -lt $_s ]; do
-               _b=$(printf '\\0%03o' $(( (_v >> (8 * _i)) & 255 )))
+               _b=$(printf '\\%03o' $(( (_v >> (8 * _i)) & 255 )))
                if [ "$be" = 1 ]; then _e="$_b$_e"; else _e="$_e$_b"; fi
                _i=$(( _i + 1 ))
        done
-       printf '%b' "$_e" | dd of="$elf" bs=1 seek=$_o conv=notrunc 2>/dev/null ||
+       printf "$_e" | dd of="$elf" bs=1 seek=$_o conv=notrunc 2>/dev/null ||
                die "cannot patch $elf"
 }