-
Notifications
You must be signed in to change notification settings - Fork 1.5k
AIX: add collector/python CGO flags and rtloader changes #49108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gh-worker-dd-mergequeue-cf854d
merged 5 commits into
main
from
pgimalac/aix-collector-python
Apr 14, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
43e5972
AIX: add collector/python CGO flags and rtloader changes
pgimalac 4ccda6a
fix: restore changes from other PRs inadvertently reverted
pgimalac 5da3877
fix: restore provider_str in three.h
pgimalac 4f55fbb
fix: remove build script reference from init.go comment
pgimalac ec1b744
fix: clean up python_aix.go comment
pgimalac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Unless explicitly stated otherwise all files in this repository are licensed | ||
| // under the Apache License Version 2.0. | ||
| // This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
| // Copyright 2016-present Datadog, Inc. | ||
|
|
||
| //go:build aix && python | ||
|
|
||
| package python | ||
|
|
||
| // Force libpython.so into the agent binary's XCOFF startup-load chain. | ||
| // | ||
| // Background | ||
| // ---------- | ||
| // Python C extension modules (lib-dynload/_decimal.so, etc.) carry Python API | ||
| // symbols (PyArg_ParseTuple, PyBool_FromLong, …) with no explicit library | ||
| // dependency in their XCOFF loader section (IMPid = "."). On AIX, such | ||
| // unresolved symbols are looked up in the process-global symbol table, which | ||
| // is populated only by libraries that appear in the XCOFF startup-load chain | ||
| // (i.e. in the XCOFF loader section of the main executable or its startup- | ||
| // linked dependencies). | ||
| // | ||
| // Without this file, libpython.so is loaded only via dlopen, transitively | ||
| // through libdatadog-agent-three.so when rtloader initialises Python. A | ||
| // dlopen-loaded library does NOT add its symbols to the global symbol table. | ||
| // As a result every Python C extension fails with: | ||
| // | ||
| // ImportError: Symbol PyXxx is not exported from dependent module agent. | ||
| // | ||
| // Fix | ||
| // --- | ||
| // The init() function below calls C.Py_IsInitialized() once at process startup. | ||
| // Go's CGO layer sees this Go→C call and emits a //go:cgo_import_dynamic | ||
| // directive that places libpython.a(shr_64.o) in the agent binary's XCOFF | ||
| // loader section. Consequently libpython.so is loaded at process startup, | ||
| // before any Python C extension module is imported, and all Python API | ||
| // symbols enter the global symbol table where the extension modules can find them. | ||
| // | ||
| // Note: a C-internal reference (static void* holding &Py_IsInitialized) is NOT | ||
| // sufficient — Go's linker only generates XCOFF import entries for symbols that | ||
| // are called from the Go side through CGO. A direct Go→C call is required. | ||
| // | ||
| // Py_IsInitialized() returns 0 when called here (Python not yet started) and | ||
| // has no side effects — it is a safe, idempotent read of an internal flag. | ||
| // | ||
| // Part 2 — Exporting Python API symbols from the agent binary | ||
| // The -bE:python.exp flag (passed via CGO_LDFLAGS at build time, NOT via | ||
| // #cgo LDFLAGS which would be rejected by Go's CGO security filter) causes the | ||
| // linker to add all Python API symbols to the agent binary's own EXP | ||
| // (export) table. Extension modules have Python API symbols with IMPid="." | ||
| // in their XCOFF, meaning "find in the main program's EXP table". Without | ||
| // -bE, those symbols are not exported from the agent and every extension fails: | ||
| // | ||
| // ImportError: Symbol PyXxx is not exported from dependent module agent. | ||
| // | ||
| // With -bE:python.exp, the agent exports the symbols and extensions load cleanly. | ||
|
|
||
| /* | ||
| #cgo LDFLAGS: -L${SRCDIR}/../../../embedded/lib -lpython3 | ||
|
|
||
| // Forward declaration — we do not include Python.h to avoid pulling in | ||
| // the entire CPython header tree; Py_IsInitialized has a stable ABI. | ||
| extern int Py_IsInitialized(void); | ||
| */ | ||
| import "C" | ||
|
|
||
| func init() { | ||
| // Call Py_IsInitialized() to create a live Go→C reference. This forces | ||
| // the CGO linker to emit a //go:cgo_import_dynamic for Py_IsInitialized, | ||
| // placing libpython.a(shr_64.o) in the XCOFF startup-load chain. | ||
| // Python is not yet started here so the call always returns 0; we discard | ||
| // the result. There are no side effects. | ||
| _ = C.Py_IsInitialized() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fields are not ordered the same way on AIX and Linux, and some types also change, so this is a simple way to fix that without having to use macros