Skip to content

rootfs_script: on glibc, keep libstdc++ only when the image names it - #2867

Merged
openipc-ai merged 3 commits into
masterfrom
libstdcpp-glibc-unreferenced
Nov 15, 2026
Merged

openipc-ai merged 3 commits into
masterfrom
libstdcpp-glibc-unreferenced

Conversation

@openipc-ai

@openipc-ai openipc-ai commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

`ssc338q_ultimate` has failed on master since 4cc6476 with `rootfs.squashfs: [8196KB/8192KB]` (run 43742671078, job 132900013341). Its last passing build was 8184 KB.

Dead weight. In the published `openipc.ssc338q-nor-ultimate` image (2026-11-14), `/usr/lib/libstdc++.so.6.0.32` is 1.4 MB, 427 KB of xz, and nothing on the image refers to it. No ELF has it as DT_NEEDED, and no file holds the string `libstdc++.so`. The only C++ program, zerotier-one, carries its C++ runtime statically (its NEEDED list is libatomic, libminiupnpc, libnatpmp, libm, libgcc_s, libc). It ships because `rootfs_script.sh` has kept libstdc++ on every glibc board unconditionally, since the script was first written in 70c4ed5 (2023), with no reason recorded.

Change. On a glibc board that matches none of the existing `CONF` keep-list entries, libstdc++ is now kept only if some file on the image names `libstdc++.so`. This is the same raw-byte test `prune-libnl.sh` uses: it catches DT_NEEDED and dlopen()ed names, and over-matches in the safe direction (a mere mention keeps it). It also requires the scan to see `libc.so` somewhere before it trusts an empty result. The `CONF` keep-list and the musl/uClibc behaviour are unchanged.

Checked locally against the extracted ssc338q_ultimate rootfs: it drops libstdc++. With a file added that names `libstdc++.so.6`, it keeps it.

The other glibc boards (av300, cv500, dv300, hi3536dv100, ssc30kq/kd, ssc338q_lite, rv11xx) keep libstdc++ where their vendor libraries link it, and lose it where nothing does. This PR touches the post-build script, so CI builds the full matrix and covers them.

Testing. This has not run on a camera; I have no glibc board here. What was checked: the extracted ssc338q_ultimate image, where no ELF lists libstdc++ in its dynamic section (readelf over every binary and library) and no file contains the string. DT_NEEDED entries are stored as plain strings, so a linked vendor library cannot slip past the byte scan. The only way to miss is a library name assembled at runtime from pieces. CI builds every glibc board, and any whose images reference libstdc++ will keep it.

ssc338q_ultimate has failed on master since 4cc6476: rootfs.squashfs 8196/8192 KB (run 43742671078, job 132900013341). Its last pass was 8184 KB.

Since this script was written (70c4ed5, 2023), every glibc board has kept libstdc++ whatever it links. On ssc338q_ultimate nothing does: no DT_NEEDED and no dlopen string anywhere in the image. zerotier-one, its only C++ program, carries its C++ runtime statically. Yet the image carries the 1.4 MB library, 427 KB of xz.

A glibc board now keeps it only when some file on the image names libstdc++.so. That is a raw byte match, so it catches DT_NEEDED and dlopen()ed names and over-matches in the safe direction. As in prune-libnl.sh, the scan must first see libc.so somewhere before an empty result is trusted. musl/uClibc boards and the CONF keep-list are unchanged.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Prune unreferenced libstdc++ from glibc root filesystems

🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Remove unused libstdc++ from glibc images to recover rootfs space, including on ssc338q_ultimate.
• Keep it when image files name the library, or when the scan cannot be validated.
• Preserve existing keep-list and non-glibc behavior.
Diagram

graph TD
  C["Build config"] --> K{"Keep-list match?"} -->|no| G{"glibc?"} -->|yes| S["Scan image"] --> V{"libc seen, stdc++ absent?"} -->|yes| D["Remove libstdc++"]
  K -->|yes| P["Keep libstdc++"]
  G -->|no| D
  V -->|no| P
Loading
High-Level Assessment

The image-content scan fits the existing pruning strategy: it detects linked and literal runtime references without maintaining board-specific exceptions. A DT_NEEDED-only check would miss dlopen references, while an allowlist would require ongoing maintenance.

Files changed (1) +20 / -2

Bug fix (1) +20 / -2
rootfs_script.shConditionally prune libstdc++ on glibc images +20/-2

Conditionally prune libstdc++ on glibc images

• Removes glibc from the unconditional keep-list. For glibc images outside that list, it scans files for libstdc++.so and deletes the library only when libc.so is found but no libstdc++ reference is found. Existing keep-list and non-glibc pruning behavior remain unchanged.

general/scripts/rootfs_script.sh

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Libstdc++ removal lacks on-device proof 📘 Rule violation ☼ Reliability
Description
The new glibc branch in rootfs_script.sh deletes /usr/lib/libstdc++* whenever a raw-byte grep
finds no libstdc++.so string, changing the image contents of every glibc board outside the CONF
list. The only evidence is a size figure and a local scan of one extracted ssc338q_ultimate rootfs,
while CI only builds images and cannot show that a camera still boots, streams, or loads a vendor
library that links libstdc++.
Code

general/scripts/rootfs_script.sh[R41-43]

+		if [ -n "${libc_seen}" ] && [ -z "${stdcpp_used}" ]; then
+			echo "rootfs_script: nothing on this glibc image names libstdc++.so, dropping it"
+			rm -f ${TARGET_DIR}/usr/lib/libstdc++*
Evidence
The change alters what the firmware does on a camera by removing a runtime library from every
matching glibc image. The PR cites no before/after boot, dmesg or stream output from a real board
and relies on CI for behaviour CI does not exercise, so the hardware evidence the rule requires is
missing.

Rule 3: Hardware evidence is present and honest
general/scripts/rootfs_script.sh[41-44]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The glibc branch of `general/scripts/rootfs_script.sh` now removes `/usr/lib/libstdc++*` on every glibc board that matches no `CONF` entry, based only on a raw-byte scan of the build output. The PR shows a size figure and a local scan of one rootfs. It has no before/after boot, dmesg or stream evidence from a real camera, and it relies on CI for behaviour CI does not exercise.
## Fix Focus Areas
- general/scripts/rootfs_script.sh[27-48]
## Recommended Fix
Add to the PR description, for at least one affected glibc board (for example ssc338q_ultimate), before and after boot logs or dmesg, plus a stream check. Confirm that no vendor binary or dlopen path needs libstdc++ that the byte scan could miss. If hardware evidence cannot be obtained, state that plainly and scope the change to the boards that were tested.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Builds in spaced paths retain libstdc++ ✓ Resolved
Description
The new find ${TARGET_DIR} scans split an unquoted target path into separate arguments, and the
new rm command also leaves that path unquoted. When a glibc image is built under a directory
containing spaces, the scan cannot reliably inspect its files and removal can silently miss the
library, leaving the image over its size limit.

Grey Divider

Tip of the day
💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@openipc-ai

Copy link
Copy Markdown
Collaborator Author

On the Qodo review:

  1. On-device proof. That is fair; I have no glibc camera. The description now says so plainly and lists what was checked. It also explains why the byte scan cannot miss a linked library: DT_NEEDED names are stored as plain strings in the binary.
  2. Paths with spaces. Agreed. 9706f3f and 5bebdab quote TARGET_DIR in both scans and in the removal, and quote BR2_CONFIG in the new glibc check. Re-tested from a target directory with a space in its name: the library is dropped there as before.

@openipc-ai

Copy link
Copy Markdown
Collaborator Author

CI: 150 firmware builds pass, among them every glibc board. ssc338q_ultimate is at rootfs.squashfs: [7756KB/8192KB] (8196 KB on master); its log shows "nothing on this glibc image names libstdc++.so, dropping it". The one red, hi3516ev300_neo, is the overflow #2866 fixed on master after this branch was cut. The remaining Qodo item (no on-device test) is stated in the description. Merging.

@openipc-ai
openipc-ai merged commit 39d180d into master Nov 15, 2026
154 of 156 checks passed
@openipc-ai
openipc-ai deleted the libstdcpp-glibc-unreferenced branch November 15, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant