Skip to content

Commit 4353488

Browse files
authored
fix: remove redundant -Wl,-z,relro,-z,now to fix UnsatisfiedLinkError on 16k-page-size builds (#563)
* fix: remove -Wl,-z,relro,-z,now to fix UnsatisfiedLinkError on 16k-page-size builds Fixes #562 — crash on Samsung S21 Plus (Android 14) with 3.1.1-16k-min: dlopen failed: can't enable GNU RELRO protection for libCGEExt.so: Out of memory Root cause: target_link_options(CGE PUBLIC ... -Wl,-z,relro,-z,now) propagated these flags to CGEExt via PUBLIC linkage. With 16KB page alignment enabled, the linker pads PT_GNU_RELRO to 16KB boundaries, making MemSiz (~10KB) far exceed the actual RW LOAD segment size (~1.5KB). The Android dynamic linker then calls mprotect() over a region larger than what was mapped, which fails with ENOMEM on devices under memory pressure. Android (API 23+) enforces full RELRO by default; these flags are redundant. Changes: - CMakeLists.txt: remove -Wl,-z,relro,-z,now; change scope to PRIVATE so the remaining -fPIE -fPIC -pie flags do not propagate unnecessarily. The -Wl,-z,max-page-size=16384 block retains PUBLIC scope so CGEExt inherits 16KB alignment automatically via CMake interface propagation. - cgeDemo/build.gradle: add disableVideoModule() helper and make the testDemoWithGradleLibs dependency string dynamic (supports all four AAR variants: default, -16k, -min, -16k-min)." * fix: address review comments in CMakeLists.txt - Remove redundant Chinese comment '# 非 Debug 模式下添加 -O3' (keep English only) - Fix full-width comma (U+FF0C) to ASCII comma in RELRO note comment - Remove target_link_options(CGE PRIVATE -fPIE -fPIC -pie): these flags are inappropriate/redundant for a SHARED library; CMake handles -fPIC automatically * chore: bump version to 3.1.2
1 parent c494765 commit 4353488

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

CHANGE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
====== Changelist =========
33

4+
# 2026-2 Version 3.1.2 #
5+
6+
1. Fix UnsatisfiedLinkError crash on 16KB-page-size builds (Samsung S21+ / Android 14): remove redundant `-Wl,-z,relro,-z,now` linker flags from CMakeLists.txt. Android API 23+ enforces full RELRO by default; the explicit flags caused `PT_GNU_RELRO MemSiz` to exceed the mapped RW LOAD segment on 16KB-aligned builds, triggering an `mprotect()` failure with `ENOMEM`. (Fixes #562)
7+
48
# 2018-6 Version 2.5.0 #
59

610
1. Add class `org.wysaid.view.CameraGLSurfaceViewWithBuffer` to do camera preview with buffer.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ext {
3838
minSdkVersion : 21,
3939
targetSdkVersion : 25, // higher target version needs more storage permission request.
4040
versionCode : 2,
41-
versionName : "3.1.1",
41+
versionName : "3.1.2",
4242
applicationId : "org.wysaid.cgeDemo",
4343
appcompatX : "1.2.0",
4444
ndkVersion : "26.3.11579264",

cgeDemo/build.gradle

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ def testDemoWithGradleLibs() {
1919
return gradle.ext != null && gradle.ext.has("testDemoWithGradleLibs") && gradle.ext.testDemoWithGradleLibs;
2020
}
2121

22+
def disableVideoModule() {
23+
return gradle.ext != null && gradle.ext.has("disableVideoModule") && gradle.ext.disableVideoModule;
24+
}
25+
2226
android {
2327
compileSdkVersion rootProject.ext.android.compileSdkVersion
2428
buildToolsVersion rootProject.ext.android.buildToolsVersion
@@ -55,7 +59,13 @@ android {
5559
dependencies {
5660
implementation fileTree(dir: 'libs', include: ['*.jar'])
5761
if (testDemoWithGradleLibs()) {
58-
implementation 'org.wysaid:gpuimage-plus:3.1.1'
62+
// Dynamically select the correct AAR variant based on local.properties flags.
63+
// This allows testing specific published variants (e.g. 3.1.1-16k-min) from maven.
64+
def baseVersion = rootProject.ext.android.versionName
65+
def variant = ''
66+
if (enable16kPageSizes()) variant += '-16k'
67+
if (disableVideoModule()) variant += '-min'
68+
implementation "org.wysaid:gpuimage-plus:${baseVersion}${variant}"
5969
} else {
6070
implementation project(':library')
6171
}

library/src/main/jni/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ endif()
8080

8181
target_compile_definitions(CGE PUBLIC ANDROID_NDK=1 CGE_LOG_TAG=\"libCGE\" CGE_TEXTURE_PREMULTIPLIED=1 _CGE_DISABLE_GLOBALCONTEXT_=1 _CGE_ONLY_FILTERS_=1)
8282
83-
# 非 Debug 模式下添加 -O3
83+
# Add -O3 in non-Debug mode
8484
target_compile_options(CGE PRIVATE $<$<NOT:$<CONFIG:Debug>>:-O3>)
8585
86-
target_link_options(CGE PUBLIC -fPIE -fPIC -pie -Wl,-z,relro,-z,now)
86+
# Note: -Wl,-z,relro,-z,now is intentionally omitted here, fixing issue: <https://github.com/wysaid/android-gpuimage-plus/issues/562>
87+
# Android API 23+ enforces full RELRO by default; no explicit linker hardening flags are needed.
8788
8889
target_link_libraries(CGE PUBLIC
8990
GLESv2

0 commit comments

Comments
 (0)