Skip to content

Shrink binary 14-49% and add qemu-arm CI tests#4

Merged
widgetii merged 1 commit intomasterfrom
shrink-binary
Apr 3, 2026
Merged

Shrink binary 14-49% and add qemu-arm CI tests#4
widgetii merged 1 commit intomasterfrom
shrink-binary

Conversation

@widgetii
Copy link
Copy Markdown
Member

@widgetii widgetii commented Apr 3, 2026

Summary

  • Shrink ELF binary across all 6 toolchains by replacing heavy libc imports with lightweight alternatives
  • Add qemu-arm functional tests to CI (4 tests × 6 toolchains = 24 tests)

Measured results (stripped, before UPX)

Toolchain Before After Saved
hisiv300 uClibc 5456 4688 768 (14%)
hisiv500 uClibc 5464 4680 784 (14%)
hisiv510 uClibc 5464 4680 784 (14%)
hisiv600 glibc 5724 4908 816 (14%)
himix100 uClibc 5268 4680 588 (11%)
himix200 glibc 9576 4908 4668 (49%)

What changed

Source (uget.c):

  • sscanf → hand-parsed HTTP status code (removes PLT entry + format string)
  • getaddrinfo/freeaddrinfogethostbyname (IPv4-only, sufficient for HiSilicon targets)
  • strncat/strcpy/strlen chain → bufcat() helper (biggest win: -4 PLT entries)
  • execlpexecl (absolute path, no PATH search needed)

Build (Makefile):

  • -ffunction-sections -fdata-sections + -Wl,--gc-sections
  • Strip .eh_frame, .eh_frame_hdr, .ARM.attributes, .jcr

CI (.github/workflows/release.yml):

  • Install qemu-user, run 4 functional tests per toolchain after build

Test plan

  • Compiled on all 6 toolchains locally
  • 24/24 qemu-arm tests pass locally (no args, bad args, HTTP GET, HTTP 404)
  • CI green on all 6 matrix entries

🤖 Generated with Claude Code

Source changes:
- Replace sscanf with hand-parsed HTTP status code
- Replace getaddrinfo with gethostbyname (IPv4-only, sufficient for target HW)
- Replace strncat/strcpy/strlen chain with bufcat() — biggest win, drops 4 PLT entries
- execlp → execl (absolute path, no PATH search needed)
- Remove unused includes (stdio.h, stddef.h) and dead NDEBUG guard

Build changes:
- Add -ffunction-sections -fdata-sections + -Wl,--gc-sections for dead code elimination
- Strip .eh_frame, .eh_frame_hdr, .ARM.attributes, .jcr sections

Measured results (stripped, before UPX):
  hisiv300 uClibc: 5456 → 4688 (-14%)
  hisiv500 uClibc: 5464 → 4680 (-14%)
  hisiv510 uClibc: 5464 → 4680 (-14%)
  hisiv600 glibc:  5724 → 4908 (-14%)
  himix100 uClibc: 5268 → 4680 (-11%)
  himix200 glibc:  9576 → 4908 (-49%)

CI: add qemu-arm functional tests (no args, bad args, HTTP GET, 404) for all 6 toolchains.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@widgetii widgetii merged commit 98a2e07 into master Apr 3, 2026
7 checks passed
@widgetii widgetii deleted the shrink-binary branch April 3, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant