Re: meta: scripts - relocation script adapted to support big-endian machines


Alexandre Belloni
 

Hello,

This build is carrying both this patch and

meta: rust: Bug fix for target definitions returning 'NoneType'

which is now present in master.

Could you check:

https://autobuilder.yoctoproject.org/typhoon/#/builders/106/builds/3963/steps/11/logs/stdio

ERROR: rust-cross-cortexa8hf-neon-glibc-1.59.0-r0 do_rust_gen_targets: Error executing a python function in exec_func_python() autogenerated:
The stack trace of python calls that resulted in this exception/failure was:
File: 'exec_func_python() autogenerated', lineno: 2, function: <module>
0001:
*** 0002:do_rust_gen_targets(d)
0003:
File: '/home/pokybuild/yocto-worker/beaglebone-alt/build/meta/recipes-devtools/rust/rust-cross.inc', lineno: 19, function: do_rust_gen_targets
0015: if arch == "arm" and target_is_armv7(d):
0016: arch = 'armv7'
0017: features = d.getVar('TARGET_LLVM_FEATURES') or ""
0018: cpu = d.getVar('TARGET_LLVM_CPU')
*** 0019: rust_gen_target(d, thing, wd, features, cpu, arch, abi)
0020:}
0021:
0022:# Otherwise we'll depend on what we provide
0023:INHIBIT_DEFAULT_RUST_DEPS = "1"
File: '/home/pokybuild/yocto-worker/beaglebone-alt/build/meta/recipes-devtools/rust/rust-common.inc', lineno: 330, function: rust_gen_target
0326: # build tspec
0327: tspec = {}
0328: tspec['llvm-target'] = d.getVarFlag('LLVM_TARGET', arch_abi)
0329: tspec['data-layout'] = d.getVarFlag('DATA_LAYOUT', arch_abi)
*** 0330: tspec['max-atomic-width'] = int(d.getVarFlag('MAX_ATOMIC_WIDTH', arch_abi))
0331: tspec['target-pointer-width'] = d.getVarFlag('TARGET_POINTER_WIDTH', arch_abi)
0332: tspec['target-c-int-width'] = d.getVarFlag('TARGET_C_INT_WIDTH', arch_abi)
0333: tspec['target-endian'] = d.getVarFlag('TARGET_ENDIAN', arch_abi)
0334: tspec['arch'] = arch_to_rust_target_arch(rust_arch)
Exception: TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'


I expect other similar failures in https://autobuilder.yoctoproject.org/typhoon/#/builders/83/builds/3478

On 05/04/2022 15:28:19+0530, Sundeep KOKKONDA wrote:
relocate_sdk.py was developed for little-endian architures and when tries
to install SDK for big-endian machines errors like below will be shown.
Error: struct.error: unpack requires a string argument of length 32. SDK could
not be set up. Relocate script failed. Abort!
Error: IOError: [Errno 22] Invalid argument. SDK could not be set up. Relocate
script failed. Abort!

To fix this, script is modified to support big-endian architecture.

Signed-off-by: Sundeep KOKKONDA <sundeep.kokkonda@...>
---
scripts/relocate_sdk.py | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/scripts/relocate_sdk.py b/scripts/relocate_sdk.py
index 8c0fdb986a..4ed8bfc0d1 100755
--- a/scripts/relocate_sdk.py
+++ b/scripts/relocate_sdk.py
@@ -30,9 +30,16 @@ else:
old_prefix = re.compile(b("##DEFAULT_INSTALL_DIR##"))

def get_arch():
+ global endian_prefix
f.seek(0)
e_ident =f.read(16)
- ei_mag0,ei_mag1_3,ei_class = struct.unpack("<B3sB11x", e_ident)
+ ei_mag0,ei_mag1_3,ei_class,ei_data,ei_version = struct.unpack("<B3sBBB9x", e_ident)
+
+ # ei_data = 1 for little-endian & 0 for big-endian
+ if ei_data == 1:
+ endian_prefix = '<'
+ else:
+ endian_prefix = '>'

if (ei_mag0 != 0x7f and ei_mag1_3 != "ELF") or ei_class == 0:
return 0
@@ -51,11 +58,11 @@ def parse_elf_header():

if arch == 32:
# 32bit
- hdr_fmt = "<HHILLLIHHHHHH"
+ hdr_fmt = endian_prefix + "HHILLLIHHHHHH"
hdr_size = 52
else:
# 64bit
- hdr_fmt = "<HHIQQQIHHHHHH"
+ hdr_fmt = endian_prefix + "HHIQQQIHHHHHH"
hdr_size = 64

e_type, e_machine, e_version, e_entry, e_phoff, e_shoff, e_flags,\
@@ -64,9 +71,9 @@ def parse_elf_header():

def change_interpreter(elf_file_name):
if arch == 32:
- ph_fmt = "<IIIIIIII"
+ ph_fmt = endian_prefix + "IIIIIIII"
else:
- ph_fmt = "<IIQQQQQQ"
+ ph_fmt = endian_prefix + "IIQQQQQQ"

""" look for PT_INTERP section """
for i in range(0,e_phnum):
@@ -105,17 +112,17 @@ def change_interpreter(elf_file_name):

def change_dl_sysdirs(elf_file_name):
if arch == 32:
- sh_fmt = "<IIIIIIIIII"
+ sh_fmt = endian_prefix + "IIIIIIIIII"
else:
- sh_fmt = "<IIQQQQIIQQ"
+ sh_fmt = endian_prefix + "IIQQQQIIQQ"

""" read section string table """
f.seek(e_shoff + e_shstrndx * e_shentsize)
sh_hdr = f.read(e_shentsize)
if arch == 32:
- sh_offset, sh_size = struct.unpack("<16xII16x", sh_hdr)
+ sh_offset, sh_size = struct.unpack(endian_prefix + "16xII16x", sh_hdr)
else:
- sh_offset, sh_size = struct.unpack("<24xQQ24x", sh_hdr)
+ sh_offset, sh_size = struct.unpack(endian_prefix + "24xQQ24x", sh_hdr)

f.seek(sh_offset)
sh_strtab = f.read(sh_size)
--
2.25.1


--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Join openembedded-core@lists.openembedded.org to automatically receive all group messages.