Skip to content

fix(simulator): build v4l2_capture as position-independent code - #144

Merged
odudex merged 1 commit into
odudex:masterfrom
Gabriel-Moya:fix/simulator-webcam-pie
Aug 18, 2026
Merged

fix(simulator): build v4l2_capture as position-independent code#144
odudex merged 1 commit into
odudex:masterfrom
Gabriel-Moya:fix/simulator-webcam-pie

Conversation

@Gabriel-Moya

Copy link
Copy Markdown
Contributor

Problem

The desktop simulator fails to link with -DSIM_WEBCAM=ON on toolchains where GCC is not configured with --enable-default-pie (reproduced on Fedora 44, GCC 16.1.1):

/usr/bin/ld.bfd: libv4l2_capture.a(v4l2_capture.c.o): relocation
R_X86_64_32 against `.rodata' can not be used when making a PIE
object; recompile with -fPIE

kern_simulator is linked with -pie (intentional hardening - the simulator parses untrusted input). A static archive is linked object-by-object into the executable, so objects compiled without -fPIC cannot be used. v4l2_captue did not set POSITION_INDEPENDENT_CODE, so its .text carried 15 absolute R_X86_64_PC32.

The lvgl and wally targets already set this property; v4l2_capture was added later and did not. On Debian/Ubuntu, GCC defaults to PIE, so the objects were position independent by accident and the bug stayed hidden.

Change

One line: set POSITION_INDEPENDENT_CODE ON on the v4l2_capture target, matching what lvgl and wally already do. Placed after the if(APPLE)/else() block so it covers both the V4L2 and AVFoundation variants.

Testing

  • cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug -DSIM_WEBCAM=ON + build: links successfully (previously failed).
  • Build without SIM_WEBCAM: unaffected.
  • ctest: storage_smoke passes.

Impact

Simulator build system only. No device code path, no firmware build, no change to the simulator/firmware separation. Hardening flags (-pie, relro, now, noexecstack) are preserved. This makes the build honor than weakening them.

kern_simulator links with -pie, but the v4l2_capture static library
was compiled without -fPIC. On toolchains where GCC is not configured
with --enable-default-pie (e.g. Fedora 44), linking with
-DSIM_WEBCAM=ON fails:

  relocation R_X86_64_32 against `.rodata` can not be used when
  making a PIE object; recompile with -fPIE

A static archive is linked object-by-object into the executable, so
its relocations must be compatible with a PIR output. The lvgl and
wally targets already set POSITION_INDEPENDENT_CODE; v4l2_capture was
added later and did not. On Debian/Ubuntu the objects were position
independent by compiler default, which masked the problem.

Simulator-only change: it does not touch any device code path.
@odudex
odudex merged commit 7d7358c into odudex:master Aug 18, 2026
11 checks passed
@odudex

odudex commented Aug 18, 2026

Copy link
Copy Markdown
Owner

Thank you!

@Gabriel-Moya
Gabriel-Moya deleted the fix/simulator-webcam-pie branch August 18, 2026 13:01
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.

2 participants