diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-06 17:24:17 -0700 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-03-09 03:09:22 -0600 |
commit | b8f3fe4923002f3978b0f8d1710b678da629e2c5 (patch) | |
tree | 86ee9b382d1c993fe21003df5340c8d23a269f3f /build-aux | |
parent | a8398b214dd6bb27cf9f8b091f0ed6fae87eb8e4 (diff) |
stack.c.gen: INFRA: Add a proper way to handle .init_array.*
Diffstat (limited to 'build-aux')
-rwxr-xr-x | build-aux/stack.c.gen | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/build-aux/stack.c.gen b/build-aux/stack.c.gen index 0a77c1a..2b7feef 100755 --- a/build-aux/stack.c.gen +++ b/build-aux/stack.c.gen @@ -412,6 +412,12 @@ re_call_other = re.compile(r"(?P<func>[^(]+)\(.*") class Plugin(typing.Protocol): def is_intrhandler(self, name: QName) -> bool: ... + + # init_array returns a list of functions that are placed in the + # `.init_array.*` section; AKA functions marked with + # `__attribute__((constructor))`. + def init_array(self) -> typing.Collection[QName]: ... + def extra_nodes(self) -> typing.Collection[Node]: ... def indirect_callees( self, loc: str, line: str @@ -465,6 +471,9 @@ class CmdPlugin: def is_intrhandler(self, name: QName) -> bool: return False + def init_array(self) -> typing.Collection[QName]: + return [] + def extra_nodes(self) -> typing.Collection[Node]: return [] @@ -532,6 +541,9 @@ class LibObjPlugin: def is_intrhandler(self, name: QName) -> bool: return False + def init_array(self) -> typing.Collection[QName]: + return [] + def extra_nodes(self) -> typing.Collection[Node]: return [] @@ -569,6 +581,9 @@ class LibHWPlugin: "dmairq_handler", ] + def init_array(self) -> typing.Collection[QName]: + return [] + def extra_nodes(self) -> typing.Collection[Node]: return [] @@ -605,6 +620,9 @@ class LibCRPlugin: def is_intrhandler(self, name: QName) -> bool: return str(name.base()) in ("_cr_gdb_intrhandler",) + def init_array(self) -> typing.Collection[QName]: + return [] + def extra_nodes(self) -> typing.Collection[Node]: return [] @@ -621,6 +639,9 @@ class LibCRIPCPlugin: def is_intrhandler(self, name: QName) -> bool: return False + def init_array(self) -> typing.Collection[QName]: + return [] + def extra_nodes(self) -> typing.Collection[Node]: return [] @@ -723,6 +744,9 @@ class Lib9PPlugin: def is_intrhandler(self, name: QName) -> bool: return False + def init_array(self) -> typing.Collection[QName]: + return [] + def extra_nodes(self) -> typing.Collection[Node]: return [] @@ -770,6 +794,9 @@ class LibMiscPlugin: def is_intrhandler(self, name: QName) -> bool: return False + def init_array(self) -> typing.Collection[QName]: + return [] + def extra_nodes(self) -> typing.Collection[Node]: return [] @@ -809,6 +836,9 @@ class PicoFmtPlugin: def is_intrhandler(self, name: QName) -> bool: return False + def init_array(self) -> typing.Collection[QName]: + return [] + def extra_nodes(self) -> typing.Collection[Node]: return [] @@ -847,15 +877,18 @@ class PicoFmtPlugin: class PicoSDKPlugin: - app_init_array: typing.Collection[QName] + get_init_array: typing.Callable[[], typing.Collection[QName]] + app_init_array: typing.Collection[QName] | None app_preinit_array: typing.Collection[QName] def __init__( self, *, - app_init_array: typing.Collection[QName], + get_init_array: typing.Callable[[], typing.Collection[QName]], ) -> None: - self.app_init_array = app_init_array + # grep for '__attribute__((constructor))'. + self.get_init_array = get_init_array + self.app_init_array = None # git grep '^PICO_RUNTIME_INIT_FUNC\S*(' self.app_preinit_array = [ @@ -896,6 +929,9 @@ class PicoSDKPlugin: *[f"isr_irq{n}" for n in range(32)], ] + def init_array(self) -> typing.Collection[QName]: + return [] + def indirect_callees( self, loc: str, line: str ) -> tuple[typing.Collection[QName], bool] | None: @@ -936,6 +972,8 @@ class PicoSDKPlugin: return [QName("stdio_uart_in_chars")], False if "/newlib_interface.c:" in loc: if line == "*p)();": + if self.app_init_array is None: + self.app_init_array = self.get_init_array() return self.app_init_array, False if "/pico_runtime/runtime.c:" in loc: return self.app_preinit_array, False @@ -1140,6 +1178,9 @@ class TinyUSBDevicePlugin: def is_intrhandler(self, name: QName) -> bool: return False + def init_array(self) -> typing.Collection[QName]: + return [] + def extra_nodes(self) -> typing.Collection[Node]: return [] @@ -1173,6 +1214,9 @@ class NewlibPlugin: def is_intrhandler(self, name: QName) -> bool: return False + def init_array(self) -> typing.Collection[QName]: + return [QName("register_fini")] + def extra_nodes(self) -> typing.Collection[Node]: # This is accurate to # /usr/arm-none-eabi/lib/thumb/v6-m/nofp/libg.a as of @@ -1221,6 +1265,9 @@ class LibGCCPlugin: def is_intrhandler(self, name: QName) -> bool: return False + def init_array(self) -> typing.Collection[QName]: + return [] + def extra_nodes(self) -> typing.Collection[Node]: # This is accurate to # /usr/lib/gcc/arm-none-eabi/14.2.0/thumb/v6-m/nofp/libgcc.a @@ -1280,10 +1327,17 @@ def main( # pico-sdk ####################################################### if arg_pico_platform == "rp2040": + + def get_init_array() -> typing.Collection[QName]: + ret: list[QName] = [] + for plugin in plugins: + ret.extend(plugin.init_array()) + return ret + plugins += [ PicoFmtPlugin(), PicoSDKPlugin( - app_init_array=[QName("register_fini")], + get_init_array=get_init_array, ), TinyUSBDevicePlugin(arg_c_fnames), NewlibPlugin(), |