[PATCH 1/1] strip: Use debugedit instead of AWK to parse source files

Allan McRae allan at archlinux.org
Sun Jan 2 14:24:34 UTC 2022


On 3/1/22 00:20, Allan McRae wrote:
> On 2/1/22 23:51, Xiretza wrote:
>>
>> On 02/01/2022 14.44, Allan McRae wrote:
>>> On 2/1/22 23:34, Xiretza wrote:
>>>> On 02/01/2022 01.28, Morten Linderud wrote:
>>>>> From: Morten Linderud <morten at linderud.pw>
>>>>>
>>>>> This moves us from the fairly ugly AWK parsing line to debugedit which
>>>>> originally comes out of the rpm project.
>>>>>
>>>>> The original code has issues parsing anything that was not straight
>>>>> C/C++ and languages like Rust or Go would return invalid source code
>>>>> files. debugedit handles all these cases better.
>>>>>
>>>>> Signed-off-by: Morten Linderud <morten at linderud.pw>
>>>>> ---
>>>>>   scripts/libmakepkg/tidy/strip.sh.in | 13 ++++++++-----
>>>>>   1 file changed, 8 insertions(+), 5 deletions(-)
>>>>>
>>>>> diff --git a/scripts/libmakepkg/tidy/strip.sh.in 
>>>>> b/scripts/libmakepkg/tidy/strip.sh.in
>>>>> index 92a6fb15..c1d8ee3c 100644
>>>>> --- a/scripts/libmakepkg/tidy/strip.sh.in
>>>>> +++ b/scripts/libmakepkg/tidy/strip.sh.in
>>>>> @@ -36,8 +36,11 @@ build_id() {
>>>>>   }
>>>>>   source_files() {
>>>>> -    LANG=C readelf "$1" --debug-dump 2>/dev/null | \
>>>>> -        awk '/DW_AT_name +:/{name=$NF}/DW_AT_comp_dir +:/{{if 
>>>>> (name == "<artificial>") next}{if (name !~ /^[<\/]/) {printf "%s/", 
>>>>> $NF}}{print name}}'
>>>>> +    dbgsrcdir="${DBGSRCDIR:-/usr/src/debug}"
>>>>> +    local dbgsrclist="$(mktemp 
>>>>> "${startdir}/dbgsrclist.${binary##*/}.XXXXXXXXX")"
>>>>> +    LANG=C debugedit -n -b "${srcdir}" -d "${dbgsrcdir}" -l 
>>>>> "${dbgsrclist}" "$1" > /dev/null
>>>>
>>>> -d/--dest-dir actually causes paths embedded in the binary to be 
>>>> *rewritten* from -b/--base-dir. Normally, this shouldn't happen 
>>>> because all paths are already translated by -fdebug-prefix-map 
>>>> before they end up in the binary (making it equivalent to `debugedit 
>>>> --base-dir "${dbgsrcdir}"`) but if there are any $srcdir-based paths 
>>>> left for whatever reason, this modifies the binary.
>>>>
>>>> If this is something we actually want to do here, I think this 
>>>> behaviour is at least worth a source comment.
>>>>
>>>
>>> Does it?  During testing the patch I added checksums before and after 
>>> getting the source file list. This command causes no change to the file.
>>>
>>> A
>>
>> It does for me:
>>
>> $ pwd
>> /tmp/srcdir
>> $ cat main.c
>> int main() {return 0;}
>> $ gcc -g main.c
>> $ debugedit -l /dev/stdout a.out | tr '\0' '\n'
>> /tmp/srcdir/main.c
>> /tmp/srcdir/main.c
>>
>> $ sha256sum a.out
>> 893824faaf62af0cdd5c23883e45b0bd6f1f526fbe5aa89d357c9acd34bbce3e  a.out
>> $ debugedit -l /dev/stdout --base-dir /tmp/srcdir --dest-dir 
>> /tmp/dbgsrcdir a.out | tr '\0' '\n'
>> main.c
>> main.c
>> $ sha256sum a.out
>> 6e4eebd6863150cb6568d99335ff073a5ddd9585e22c5de5c4dd159e5b6bc0b2  a.out
>>
>> $ debugedit -l /dev/stdout a.out | tr '\0' '\n'
>> /tmp/dbgsrcdir/main.c
>> /tmp/dbgsrcdir/main.c
>> .
> 
> Add -n.
> 


For a better example, here is my testing code:

source_files() {
	dbgsrcdir="${DBGSRCDIR:-/usr/src/debug}"
	local dbgsrclist="$(mktemp 
"${startdir}/dbgsrclist.${binary##*/}.XXXXXXXXX")"
echo $1 >> $startdir/dbginfo
echo sha256sum-orig: $(sha256sum $1) >> $startdir/dbginfo
	LANG=C debugedit -n -b "${srcdir}" -d "${dbgsrcdir}" -l "${dbgsrclist}" 
"$1" > /dev/null
	sort -zu "${dbgsrclist}" | tr '\0' '\n'
sort -zu "${dbgsrclist}" | tr '\0' '\n' >> $startdir/dbginfo
echo sha256sum-after: $(sha256sum $1) >> $startdir/dbginfo
	rm -f "$dbgsrclist"
}


and a snippet of the output:

./usr/bin/vercmp
sha256sum-orig: 
844e2a18277df5d46544fc977a028b02b58d642bc9754d7d9868197d23f42407 
./usr/bin/vercmp
pacman/builddir/<artificial>
pacman/builddir/<built-in>
pacman/lib/libalpm/version.c
pacman/src/util/vercmp.c
sha256sum-after: 
844e2a18277df5d46544fc977a028b02b58d642bc9754d7d9868197d23f42407 
./usr/bin/vercmp




More information about the pacman-dev mailing list