[v0.1.0a5] Handled the case that no symbol is exported in .o file

This commit is contained in:
sup39 2023-07-14 23:00:42 +09:00
parent 33e7e5a8cb
commit 26db97fb12
No known key found for this signature in database
GPG key ID: 14D2E0D21140D260
3 changed files with 15 additions and 6 deletions

View file

@ -1,4 +1,6 @@
# Changelog
## 0.1.0a5
- Handled the case that no symbol is exported in .o file
## 0.1.0a4
- Added `compile_flags` property to `Gecko` class
## 0.1.0a3

View file

@ -1,6 +1,6 @@
[metadata]
name = supGecko
version = 0.1.0a4
version = 0.1.0a5
author = sup39
author_email = sms@sup39.dev
description = A helper library to write Gecko code
@ -15,7 +15,8 @@ classifiers =
License :: OSI Approved :: MIT License
[options]
packages = find:
packages = find_namespace:
include_package_data = True
python_requires = >=3.8
[options.packages.find]

View file

@ -7,10 +7,15 @@ import tempfile
import os
import subprocess
def system(argv, *args, **kwargs):
r = subprocess.run(argv, *args, capture_output=True, text=True, **kwargs)
def system(argv, *, catch=None, **kwargs):
r = subprocess.run(argv, capture_output=True, text=True, **kwargs)
if r.returncode:
raise Exception(f'Fail to run {argv[0]} (code={r.returncode}): {r.stderr}')
if catch is not None:
# catch(r) returns the alternate stdout for handled errors
o = catch(r)
# if catch(r) returns None, the error is unexpected and should be raised
if o is not None: return o
raise Exception(f'Fail to run {argv} (code={r.returncode}): {r.stderr}')
return r.stdout
def write_extra_input(x, file):
@ -83,10 +88,11 @@ def compile(
# gecko symbols
symbols = {}
errmsg_nosymbol = "section '.text' mentioned in a -j option, but not found in any input file"
lines = system([
'powerpc-eabi-objdump',
'-tj.text', distLOBJ,
]).split('\n')
], catch=lambda r: '' if r.returncode==1 and errmsg_nosymbol in r.stderr else None).split('\n')
for line in lines[4:-3]:
ch1, ch2 = line.split('\t')
addr = int(ch1.split(None, 2)[0], 16)