Skip to content

gk7102: BR2_TARGET_OPTIMIZATION=-mno-unaligned-access - #2260

Closed
shipa-2 wants to merge 1 commit into
OpenIPC:masterfrom
shipa-2:pr/gk7102-mno-unaligned-access
Closed

gk7102: BR2_TARGET_OPTIMIZATION=-mno-unaligned-access#2260
shipa-2 wants to merge 1 commit into
OpenIPC:masterfrom
shipa-2:pr/gk7102-mno-unaligned-access

Conversation

@shipa-2

@shipa-2 shipa-2 commented Aug 11, 2026

Copy link
Copy Markdown

Summary

  • Set BR2_TARGET_OPTIMIZATION=\"-mno-unaligned-access\" on gk7102_lite and gk7102s_lite to avoid ARMv6 userspace corruption from unaligned accesses.

Test plan

  • Rebuild userspace; toolchain wrapper passes -mno-unaligned-access
  • SSH + WPA2 stable on GK7102 (validated with rebuilt SDK toolchain)

Part of splitting #2256.

Made with Cursor

Avoid ARMv6 userspace corruption from unaligned LDR/STR on GK7102/GK7102S.

Co-authored-by: Cursor <cursoragent@cursor.com>
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

gk7102: disable unaligned accesses via BR2_TARGET_OPTIMIZATION

🐞 Bug fix ⚙️ Configuration changes 🕐 Less than 10 minutes

Grey Divider

AI Description

• Add -mno-unaligned-access to GK7102/GK7102S lite Buildroot target optimization.
• Prevent ARMv6 userspace corruption from unaligned LDR/STR on these SoCs.
• Ensure toolchain wrapper propagates the flag across userspace rebuilds.
Diagram

graph TD
  A["gk7102_lite_defconfig"] --> B([Buildroot config]) --> C([Toolchain wrapper]) --> D([GCC flags]) --> E([Userspace binaries]) --> F([GK7102/GK7102S runtime])
  A2["gk7102s_lite_defconfig"] --> B
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Apply flag selectively (per-package or libc-only)
  • ➕ Limits potential performance impact to suspected-problem components
  • ➕ Reduces risk of unintended side effects across all userspace packages
  • ➖ Hard to ensure full coverage if corruption source is widespread
  • ➖ More ongoing maintenance (package-specific overrides)
2. Rely on kernel alignment fixes / trap emulation
  • ➕ Avoids global compile-flag change and potential performance regressions
  • ➕ Can centralize behavior in one place (kernel)
  • ➖ May not prevent all userspace corruption scenarios depending on SoC behavior
  • ➖ Kernel-dependent behavior can vary across deployments and configurations

Recommendation: The PR’s approach (setting BR2_TARGET_OPTIMIZATION=&quot;-mno-unaligned-access&quot; at the defconfig level) is the most reliable, lowest-maintenance way to ensure all userspace is built safely for these ARMv6 targets. If performance regressions appear, consider narrowing scope to selected packages, but only if you can prove coverage for the corruption path.

Files changed (2) +4 / -0

Bug fix (2) +4 / -0
gk7102_lite_defconfigSet -mno-unaligned-access for GK7102 lite userspace builds +2/-0

Set -mno-unaligned-access for GK7102 lite userspace builds

• Adds 'BR2_TARGET_OPTIMIZATION="-mno-unaligned-access"' so Buildroot compiles userspace with unaligned accesses disabled. Intended to prevent ARMv6 userspace corruption on GK7102.

br-ext-chip-goke/configs/gk7102_lite_defconfig

gk7102s_lite_defconfigSet -mno-unaligned-access for GK7102S lite userspace builds +2/-0

Set -mno-unaligned-access for GK7102S lite userspace builds

• Adds 'BR2_TARGET_OPTIMIZATION="-mno-unaligned-access"' to ensure userspace is compiled without unaligned LDR/STR behavior. Aligns GK7102S lite behavior with the stability requirement on ARMv6.

br-ext-chip-goke/configs/gk7102s_lite_defconfig

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

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Optimization flags clobbered 🐞 Bug ➹ Performance
Description
BR2_TARGET_OPTIMIZATION is set to only -mno-unaligned-access in the GK7102 lite defconfigs,
which drops any explicit -O* optimization level from the target CFLAGS. Packages that consume
$(TARGET_CFLAGS) (e.g., ffmpeg-openipc) may then compile without the intended size/performance
optimizations, inflating binaries and slowing runtime.
Code

br-ext-chip-goke/configs/gk7102_lite_defconfig[6]

+BR2_TARGET_OPTIMIZATION="-mno-unaligned-access"
Evidence
The project enables size optimization (BR2_OPTIMIZE_S=y), and some packages rely on
$(TARGET_CFLAGS) for their optimization level; overwriting the target optimization string with
only -mno-unaligned-access risks removing the optimization level they depend on.

br-ext-chip-goke/configs/gk7102_lite_defconfig[1-8]
br-ext-chip-goke/configs/gk7102s_lite_defconfig[1-8]
general/openipc.fragment[12-16]
general/package/ffmpeg-openipc/ffmpeg-openipc.mk[52-60]

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

## Issue description
`BR2_TARGET_OPTIMIZATION` is being overwritten with only `-mno-unaligned-access`, which can remove the intended optimization level (e.g., `-Os`) for this target.

## Issue Context
This repo enables size optimization globally via `BR2_OPTIMIZE_S=y`, and several packages (e.g., ffmpeg-openipc) use `$(TARGET_CFLAGS)` directly, so the target optimization string should still include an `-O*` flag.

## Fix Focus Areas
- br-ext-chip-goke/configs/gk7102_lite_defconfig[1-8]
- br-ext-chip-goke/configs/gk7102s_lite_defconfig[1-8]

## Suggested change
Update both defconfigs to *include* the normal optimization flags plus `-mno-unaligned-access` (example: `BR2_TARGET_OPTIMIZATION="-Os -pipe -mno-unaligned-access"`), matching the project’s intended optimization mode while still preventing unaligned accesses.

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


Grey Divider

Tip of the day
💡 Did you know, you can group findings by type and pick your Finding display, from Minimal to Full

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

BR2_arm1176jzf_s=y
BR2_ARM_EABI=y

BR2_TARGET_OPTIMIZATION="-mno-unaligned-access"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remediation recommended

1. Optimization flags clobbered 🐞 Bug ➹ Performance

BR2_TARGET_OPTIMIZATION is set to only -mno-unaligned-access in the GK7102 lite defconfigs,
which drops any explicit -O* optimization level from the target CFLAGS. Packages that consume
$(TARGET_CFLAGS) (e.g., ffmpeg-openipc) may then compile without the intended size/performance
optimizations, inflating binaries and slowing runtime.
Agent Prompt
## Issue description
`BR2_TARGET_OPTIMIZATION` is being overwritten with only `-mno-unaligned-access`, which can remove the intended optimization level (e.g., `-Os`) for this target.

## Issue Context
This repo enables size optimization globally via `BR2_OPTIMIZE_S=y`, and several packages (e.g., ffmpeg-openipc) use `$(TARGET_CFLAGS)` directly, so the target optimization string should still include an `-O*` flag.

## Fix Focus Areas
- br-ext-chip-goke/configs/gk7102_lite_defconfig[1-8]
- br-ext-chip-goke/configs/gk7102s_lite_defconfig[1-8]

## Suggested change
Update both defconfigs to *include* the normal optimization flags plus `-mno-unaligned-access` (example: `BR2_TARGET_OPTIMIZATION="-Os -pipe -mno-unaligned-access"`), matching the project’s intended optimization mode while still preventing unaligned accesses.

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

@widgetii

Copy link
Copy Markdown
Member

Closing this since no reply

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