AnsweredAssumed Answered

Stripping opencl binary corrupts file

Question asked by boxerab on Nov 15, 2016
Latest reply on Nov 16, 2016 by empty_knapsack

After I generate a binary version of my kernel, I strip off .source, .llvmir and .amdil from ELF binary.

I am on windows 10 with latest crimson driver, with polaris 470.

The script I use can be found below ( I use mingw-64 tools to get objcopy and readelf executables)

 

Before I strip the binary, I can load it and create a kernel. After I strip the binary, my application crashes -CL_INVALID_KERNEL_NAME

error.

 

This works fine on my old system:

windows 7

latest crimson

cape verde HD 7700

 

Thanks,

Aaron

 

 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

#!/bin/bash

#      ^^^^- important, not /bin/sh

 

 

# see http://developer.amd.com/knowledge-base/?ID=115 for more details

 

# define a regex, in ERE form, to extract the content you want in a match group

re='machine.*(0x[[:xdigit:]]{2,}) '

 

# iterate over files, putting each in $f

for f in *; do

 

        # don't operate on files we previously generated

        [[ $f = *.stripped ]] && continue

 

        # actually run readelf, taking first matching line

        m_line=$(readelf -aW "$f" | egrep -m 1 "$re")

 

    [[ $m_line =~ $re ]] || continue # check whether we match the regex

 

    # if we get here, the regex matched; copy the first match group into a variable

    code=${BASH_REMATCH[1]}

 

    # ...and use that variable in calling objcopy

    objcopy -I elf64-x86-64  -O elf64-x86-64 -R .source -R .llvmir -R .amdil \

          --alt-machine-code="$code" \

              "$f" "$f" >/dev/null 2>&1 || { echo "Objcopy failed!" >&2; }

 

             readelf -a "$f" | grep .source

             readelf -a "$f" | grep .llvmir

             readelf -a "$f" | grep .amdil

 

done

Outcomes