[PATCH i-g-t] scripts/generate_iga64_codes: prevent objcopy from modifying the input file

Kamil Konieczny kamil.konieczny at linux.intel.com
Thu Oct 31 16:51:00 UTC 2024


Hi Jeff,
On 2024-10-30 at 11:40:54 -0700, Jeff Dagenais wrote:
> This script uses objcopy in order to dump a section. Objcopy is meant
> for copying and expects a second argument. Failing that, it uses the
> input file as output. Even though there's no intented change to the
> file, this operation still re-writes the file completely.
> 
> In most cases, this re-writes the file as it was before. But in
> cross-compilation cases, the "objcopy" program in the PATH used here
> might be different than the toolchain which generated the ELF file.
> 
> In all cases, this causes a racy re-build of the .a, and in the worst
> case, the objcopy re-written .o and .a files are actually incompatible
> with the cross-linker used downstream in the ninja build causing failure
> to find all symbols from the libs passed to this script.
> 
> ```
> ../lib/intel_batchbuffer.c:763: undefined reference to
> `gen8_gpgpu_fillfunc'
> ../lib/intel_batchbuffer.c:762: undefined reference to
> `xehp_gpgpu_fillfunc'
> [...]
> ```
> 
> The intent of the command was just to extract info from the LIBS, not
> modify them. Using /dev/null as output file ensures the input files will
> not be modified.
> 

Thank you for a patch, if possible please subscribe to ML or expect
some delay between sending e-mail and delivering it to mailing list.

+cc Andrzej Hajda <andrzej.hajda at intel.com>

> Signed-off-by: Jeff Dagenais <jeff.dagenais at gmail.com>
> ---
>  scripts/generate_iga64_codes | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/scripts/generate_iga64_codes b/scripts/generate_iga64_codes
> index d1e40b600..bbf1f7008 100755
> --- a/scripts/generate_iga64_codes
> +++ b/scripts/generate_iga64_codes
> @@ -37,7 +37,7 @@ ASMS=()
>  while  read -d $'\0' asm; do
>      test -z "$asm" && continue
>      ASMS+=( "$asm" )
> -done < <(for f in $LIBS; do objcopy --dump-section .iga64_assembly=/dev/stdout $f.p/*.o; done)
> +done < <(for f in $LIBS; do objcopy --dump-section .iga64_assembly=/dev/stdout $f.p/*.o /dev/null; done)
>  
>  # check if we need to recompile - checksum difference and compiler present
>  MD5_ASMS="$(md5sum <<< "${ASMS[@]}" | cut -b1-32)"
> -- 
> 2.43.0
> 


More information about the igt-dev mailing list