gcc: Replace the original patch with the new one that adds support for paths containing spaces in spec functions - #30252
gcc: Replace the original patch with the new one that adds support for paths containing spaces in spec functions#30252Fourish wants to merge 1 commit into
Conversation
|
Here is a simple script for testing support for directories whose paths contain spaces. #!/bin/bash
# make directory {test_dir, test_dir/normal_dir, test_dir/dir with spaces}
# make something.o to {test_dir/normal_dir/something.o, test_dir/dir with spaces/something.o}
# write main.c to test_dir/main.c
# make {test_dir/total.log, test_dir/fail.log}
# dump default specs to test_dir/specs_default
prepare() {
local normal_dir="$1"
local dir_with_space="$2"
if [[ -d "test_dir" ]]; then
return
fi
mkdir -p "test_dir"
pushd "test_dir" > /dev/null
mkdir -p "${PWD}/${normal_dir}"
mkdir -p "${PWD}/${dir_with_space}"
printf "\n" > "something.c"
printf "int main() { return 0; }\n" > "main.c"
gcc --compile something.c
cp something.o "${normal_dir}/something.o"
mv something.o "${dir_with_space}/something.o"
touch {total,fail}.log
gcc -dumpspecs > specs_default
popd > /dev/null
}
# excute cmd,
# compare output with expected_out,
# print result and log details to total.log and fail.log
expected() {
local name="$1"
local cmd="$2"
local expected_out="$3"
local got
got="$(bash -c "$cmd")"
if [[ -z "$got" && -z "$expected_out" ]] || \
[[ -n "$got" && -n "$expected_out" && "$got" == *"$expected_out"* ]]; then
printf '\033[32m%s Success\033[0m\n' "$name"
{
printf '##### %s Success #####\n' "$name"
printf 'Command:\n%s\n' "$cmd"
printf 'Expected:\n'
printf '%s\n' "$expected_out"
printf 'Got:\n'
printf '%s\n\n' "$got"
} >> total.log
return 0
else
printf '\033[31m%s Failed\033[0m\n' "$name"
{
printf '##### %s Failed #####\n' "$name"
printf 'Command:\n%s\n' "$cmd"
printf 'Expected:\n'
printf '%s\n' "$expected_out"
printf 'Got:\n'
printf '%s\n\n' "$got"
} | tee -a total.log fail.log >/dev/null
return 1
fi
}
# generate specs by appending var to the line after *segment: in specs_default
generate_specs() {
local segment="$1"
local var="$2"
local output="$3"
sed "/^\*${segment}:$/ { n; s/$/ ${var}/ }" specs_default > "${output}"
}
test_wrap() {
local id="$1"
local var="$2"
local dir="$3"
local expected_compile_out="$4"
printf 'Test %s with %s in %s\n' "$id" "$var" "$dir"
generate_specs "endfile" "${var}" "specs_${id}"
expected "Test${id} compile" \
"gcc -specs=specs_${id} main.c -B\"${dir}\" -o a.out 2>&1" \
"${expected_compile_out}"
if [[ $? -eq 0 ]] && [[ -n "$5" ]]; then
local expected_check_out="$5"
expected "Test${id} check" \
"strings a.out | grep ${expected_check_out}" \
"${expected_check_out}"
fi
}
main() {
normal_dir="normal_dir"
dir_with_space="dir with spaces"
prepare "${normal_dir}" "${dir_with_space}"
pushd "test_dir" > /dev/null
normal_dir="$PWD/${normal_dir}"
dir_with_space="$PWD/${dir_with_space}"
printf "====================\n" | tee -a {total,fail}.log > /dev/null
gcc --version | tee -a {total,fail}.log
# append_to_specs, compile_include_dir, expected_compile_out, [expected_check_out]
test_args=(
"" "${dir_with_space}" "" ""
"something.o%s" "${normal_dir}" "" "something.c"
"something.o%s" "${dir_with_space}" "" "something.c"
"%:if-exists(something.o%s)" "${normal_dir}" "" "something.c"
"%:if-exists(something.o%s)" "${dir_with_space}" "" "something.c"
"%:if-exists(%:if-exists(something.o%s))" "${normal_dir}" "" "something.c"
"%:if-exists(%:if-exists(something.o%s))" "${dir_with_space}" "" "something.c"
"non-existfile%s" "${normal_dir}" "cannot find non-existfile" ""
"%:if-exists(non-existfile%s)" "${normal_dir}" "" ""
"%:if-exists(%:if-exists(non-existfile%s))" "${normal_dir}" "" ""
)
for ((i=0; i<${#test_args[@]}; i+=4)); do
id=$(((i+4)/4))
var="${test_args[i]}"
dir="${test_args[i+1]}"
expected_compile_out="${test_args[i+2]}"
expected_check_out="${test_args[i+3]}"
test_wrap "$id" "$var" "$dir" "$expected_compile_out" "$expected_check_out"
done
popd > /dev/null
}
#set -x
main
|
support for paths containing spaces in spec functions. The old patch disrupts the evaluation of spec functions. As a result, on MinGW targets, the expression used to add the default manifest file: `%:if-exists(default-manifest.o%s)` appends `default-manifest.o` to the end of the collect2 argument list regardless of whether the file actually exists. This is not the intended behavior. However, it usually does not cause an error on MSYS2 because the `mingw-w64-gcc` package depends on the `mingw-w64-windows-default-manifest` package.
73bc104 to
f63e368
Compare
|
Is there any way you could send this upstream? |
I agree, this would benefit way more than just us upstream. If you can't for some reason I can offer to help send your patch upstream, completely credited to you. |
Actually, I sent this patch upstream before, here: https://gcc.gnu.org/pipermail/gcc-patches/2026-May/718458.html, but no maintainer has reviewed it @_@ This bug only occurs when a spec uses a command such as |
|
Maybe combining this with another enhancement would be more convincing? I'm writing a patch to add a manifest linking option at the moment, I could combine this patch with my own small patch and send it upstream with you as the author for your section of the patch, if you're alright with that of course. |
Sure, feel free to use it. :D |
The old patch disrupts the evaluation of spec functions. As a result, on MinGW targets, the expression used to add the default manifest file:
appends
default-manifest.oto the end of the collect2 argument list regardless of whether the file actually exists. This is not the intended behavior.However, it usually does not cause an error on MSYS2 because the
mingw-w64-gccpackage depends on themingw-w64-windows-default-manifestpackage.