Date: Thu, 16 Mar 2023 13:19:37 +0000 From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 269568] strip(1) creates an executable which crashes in ld-elf.so.1 Message-ID: <bug-269568-227-zogJThgPJn@https.bugs.freebsd.org/bugzilla/> In-Reply-To: <bug-269568-227@https.bugs.freebsd.org/bugzilla/> References: <bug-269568-227@https.bugs.freebsd.org/bugzilla/>
next in thread | previous in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D269568 --- Comment #2 from Fernando Apestegu=C3=ADa <fernape@FreeBSD.org> --- More info: The problem is with the GNU_STACK segment. I edited the binary and changed = the vaddr and msize to match that of the original unstripped file and the resul= ting binary runs fine. Inspecting the sources of strip(1) I found the problem is in the copy_phdr function in segments.c in this specific code: if (seg->nsec > 0) { s =3D seg->v_sec[0]; seg->vaddr =3D s->vma; seg->paddr =3D s->lma; }=20=20=20 seg->fsz =3D seg->msz =3D 0; for (i =3D 0; i < seg->nsec; i++) { s =3D seg->v_sec[i]; seg->msz =3D s->vma + s->sz - seg->vaddr; if (s->type !=3D SHT_NOBITS) seg->fsz =3D s->off + s->sz - seg->off; } Changing that part so we actually copy the program header verbatim creates = an executable that doesn't crash. This kind of behavior seems to be similar to what llvm-strip and gnustrip do. To check this, using the objects created b= y a "make kernel" and "make buildworld" strip the full binary and check the original program header and the one from the stripped binary: STRIP_CMD=3Dllvm-strip for file in $(find . -name '*.full') do t=3D$(mktemp /tmp/tmp.XXXX) "${STRIP_CMD}" -o "${t}" "${file}" diff <(readelf -l "${file}") <(readelf -l "${t}") if [[ $? -eq 0 ]] then echo "Equal program header for ${file}" else echo "Different program header for ${file}" fi rm "${t}" done llvm-strip doesn't change the program header at all nor does GNU strip. But strip(1) in base changes it quite often (RELRO, INTERP and at least in jdup= es case GNU_STACK segments). --=20 You are receiving this mail because: You are the assignee for the bug.=
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-269568-227-zogJThgPJn>