Skip to content

fix(libhsakmt): Define _GNU_SOURCE before libhsakmt.h include#8555

Merged
erman-gurses merged 3 commits into
developfrom
users/dayatsin/ROCM-26861-gnu-source-order
Jul 14, 2026
Merged

fix(libhsakmt): Define _GNU_SOURCE before libhsakmt.h include#8555
erman-gurses merged 3 commits into
developfrom
users/dayatsin/ROCM-26861-gnu-source-order

Conversation

@dayatsin-amd

@dayatsin-amd dayatsin-amd commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Move #define _GNU_SOURCE to the top of hsakmtmodel.c, before all includes, and remove the redundant #define __USE_GNU. _GNU_SOURCE must be defined before any system header is pulled in; hsakmtmodel.h, hsakmt_drm.h, and libhsakmt.h all transitively include libc/drm headers. Defining it after those includes breaks GNU extension visibility (e.g. secure_getenv) and causes compile errors in strict or sanitizer builds.

JIRA ID

JIRA ID : ROCM-26861

Test plan

Tested on dayatsin-test-01 (Ubuntu 24.04, amdclang 23.0.0 from /opt/rocm), including after removing __USE_GNU (c651d3f278):

  • Build libhsakmt / rocr-runtime with ASAN enabled (-DADDRESS_SANITIZER=ON -DTHEROCK_SANITIZER=ASAN) — full build succeeded (libhsa-runtime64.so produced)
  • Build with amdclang from TheRock/ROCm toolchain — Release hsakmt target succeeded
  • Verify hsakmtmodel.c compiles without _GNU_SOURCE ordering warnings/errors — no errors in either ASAN or Release builds

_GNU_SOURCE must be defined before any system header is pulled in;
libhsakmt.h includes pthread.h and other libc headers, so defining it
after that include breaks GNU extension visibility in some build envs.

Co-authored-by: Cursor <cursoragent@cursor.com>
hsakmtmodel.h and hsakmt_drm.h pull in amdgpu/drm headers before
libhsakmt.h, so _GNU_SOURCE must be the first definition in the TU.

Co-authored-by: Cursor <cursoragent@cursor.com>
@dayatsin-amd

Copy link
Copy Markdown
Contributor Author

Test results (dayatsin-test-01)

Host: Ubuntu 24.04.3 LTS, amdclang 23.0.0 (/opt/rocm/lib/llvm/bin/amdclang)

Test Result
ASAN full rocr-runtime build (-DADDRESS_SANITIZER=ON -DTHEROCK_SANITIZER=ASAN) PASSlibhsa-runtime64.so linked successfully
Release hsakmt build (amdclang, no sanitizer) PASShsakmtmodel.c.o compiled cleanly
hsakmtmodel.c _GNU_SOURCE / secure_getenv errors None

Note: the initial commit only moved _GNU_SOURCE above libhsakmt.h; ASAN build on this host still failed because hsakmtmodel.h/hsakmt_drm.h pull in drm/amdgpu headers first. Follow-up commit e982b6d89d moves _GNU_SOURCE before all includes (matching openclose.c).

@therock-pr-bot

Copy link
Copy Markdown

❌ PR Check — Action Required

Check Status Details
🌿 Branch Name ✅ Pass
📝 PR Title/Description ✅ Pass
Forbidden Files ✅ Pass
🧪 Unit Test ❌ Fail Error: Source/code files changed without an accompanying unit test.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: projects/rocr-runtime/libhsakmt/src/hsakmtmodel.c; no test file found
🔎 pre-commit ⏳ Pending ⏳ Still running…
🚫 Draft PR 🔜 To Be Enabled
🚩 Feature Flag 🔜 To Be Enabled
📊 Code Coverage 🔜 To Be Enabled

⚠️ 1 policy check(s) failed. Please address the issues above before this PR can be Reviewed.

🚫 Please fix the failed policies

  • ❌ Unit Test

The Not ready to Review label was added to this PR. Once all policies pass, the label is removed automatically.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

@therock-pr-bot

Copy link
Copy Markdown

🚫 Please fix the failed policies before requesting reviews.

The following policy checks failed:

  • ❌ Unit Test

The Not ready to Review label has been added to this PR.
Once all policies pass, the label will be removed automatically.

@cfreeamd cfreeamd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤖 AI-assisted pre-review (for @cfreeamd) — projects/rocr-runtime/libhsakmt/src/hsakmtmodel.c reviewed.

Comment thread projects/rocr-runtime/libhsakmt/src/hsakmtmodel.c Outdated
_GNU_SOURCE at the top of the TU already enables the same glibc
extensions; __USE_GNU is redundant and can conflict in strict builds.

Co-authored-by: Cursor <cursoragent@cursor.com>
@dayatsin-amd

Copy link
Copy Markdown
Contributor Author

Re-test after removing __USE_GNU (c651d3f278)

Host: dayatsin-test-01, Ubuntu 24.04.3 LTS, amdclang 23.0.0

Test Result
ASAN full rocr-runtime build PASS
Release hsakmt build PASS
hsakmtmodel.c compile errors None

_GNU_SOURCE alone is sufficient; __USE_GNU is redundant with it defined at the top of the TU.

@erman-gurses
erman-gurses merged commit aa9950f into develop Jul 14, 2026
27 of 30 checks passed
@erman-gurses
erman-gurses deleted the users/dayatsin/ROCM-26861-gnu-source-order branch July 14, 2026 20:15
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.

4 participants