fix(settings): app fails to launch on real hardware — misaligned relocation from packed struct pointer - #7
Open
vvzvlad wants to merge 1 commit into
Conversation
persist.strftime_format is a char* at an unaligned offset inside a __attribute__((packed)) struct. Initialising it with a string literal made the compiler emit an R_ARM_ABS32 relocation at a non-word-aligned image offset (0x78d7). The PebbleOS app loader requires relocation targets to be word-aligned and rejects the app at load time: "Invalid app relocation target[68]" -> "invalid app in bank 6" -> "Failed to start app <TimelyNG>", so the watchface never launched. The field is never read in C (the custom date format lives in adv_settings.custom_date_fmt), so initialise it to a null pointer. No struct layout change, so persisted settings stay compatible. Relocations drop 76 -> 75, all word-aligned; verified installing and launching on Pebble Time 2 (emery). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On real hardware (Pebble Time 2 /
emery) TimelyNG never launches — selectingit drops straight back to the launcher. The firmware log shows:
So the app is rejected at load time, during relocation fix-up — it is not a
heap or SDK-version problem (heap is ~99 KB free,
sdk_version5.104 matches).Root cause
persistinsrc/settings.his__attribute__((__packed__))and contains apointer member:
Because the struct is packed,
strftime_formatlands at byte offset 18. Thestatic initialiser in
src/settings.cset it to a string literal:That stores an absolute address, so the toolchain emits an
R_ARM_ABS32relocation at image offset
0x78d7(=&s_settings + 18), which is notword-aligned.
prv_apply_relocations()in the app loader requires everyrelocation target to be word-aligned and rejects the whole app when it isn't —
hence "Invalid app relocation target" and the app never runs.
This likely doesn't reproduce in every emulator/SDK (older loaders didn't
enforce the alignment check), which is why it slipped through, but the current
Core Devices firmware enforces it.
Fix
persist.strftime_formatis never read in C — the custom date format used atruntime is
adv_settings.custom_date_fmt(Timely.c,date_format == 255).So initialise the field to a null pointer instead of a literal:
A null pointer needs no relocation, so the offending
R_ARM_ABS32entrydisappears. The struct layout is unchanged, so
persist_read_data/persist_write_datastay byte-compatible with existing installs.Verification
emery: relocation count drops 76 → 75, and every remainingentry is word-aligned and in range (previously entry 68 =
0x78d7)..pbwon a real Pebble Time 2 and confirmed thewatchface launches and stays running (
app run state: RUNNING,no "invalid app" / no fault loop).
🤖 Generated with Claude Code