Skip to content

Refactor C/Fortran interfaces and enforce non-executable stack#125

Merged
williamjameshandley merged 5 commits intomasterfrom
glibc_2.41_fix
Aug 12, 2025
Merged

Refactor C/Fortran interfaces and enforce non-executable stack#125
williamjameshandley merged 5 commits intomasterfrom
glibc_2.41_fix

Conversation

@williamjameshandley
Copy link
Member

• Added the linker flag "-Wl,-z,noexecstack" in Makefile_gnu to disable executable stacks for improved security.
• In src/polychord/interfaces.F90:
move all functions defined internally in contains functions to module-level definitions with module-level variables.

This fixes the bug found in #124 which has arisen for glibc 2.41 which does not allow executable stack calls

• Added the linker flag "-Wl,-z,noexecstack" in Makefile_gnu to disable executable stacks for improved security.
• In src/polychord/interfaces.F90:
move all functions defined internally in contains functions to
module-level definitions with module-level variables.

This fixes the bug found in #124 which has arisen for glibc 2.41 which
does not allow executable stack calls
Copy link

@lukashergt lukashergt left a comment

Choose a reason for hiding this comment

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

OK, an hours marathon vibing with o3-mini high eventually revealed the problem to be a combination of needing to add some linker flags, and a re-write of the interfaces so that it does not define functions within a function's contains section.

Cool, nice to see that I wasn't too far off with my link from #124, which addresses the issue with nested functions.

This PR indeed fixes my install issue, and python run_pypolychord.py now runs without issue.

However, since this so far only modifies interfaces.F90, but I stumbled upon that little X in both interfaces.o and maximiser.o (see the last paragraph in my first post in #124), I dug a bit further. There are indeed nested functions in maximiser.F90 as well, and when adding settings.maximise = True to run_pypolychord.py, then it will segfault the moment it starts trying to maximise the likelihood. So I guess the same needs to be done for maximiser.F90.

williamjameshandley and others added 4 commits August 12, 2025 17:22
- Moved nested func() from do_maximisation contains section to module-level maximisation_func()
- Added module-level variables (func_settings, func_posterior, stored_loglikelihood, stored_prior)
- Used procedure pointers with save attribute to maintain function context
- Completes fix for Issue #124 alongside interfaces.F90 changes
- Eliminates all nested functions that cause executable stack requirements with glibc 2.41+

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Version 1.22.2 includes:
- Fixed maximiser segfaults on Arch Linux (glibc 2.41+) by eliminating nested functions
- Fixed Fortran write statement comma formatting issues
- Added Python 3.12 support and updated CI to test Python 3.8-3.12
- Complete Arch Linux compatibility for modern systems

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@williamjameshandley williamjameshandley merged commit 3ade644 into master Aug 12, 2025
11 checks passed
AdamOrmondroyd pushed a commit to AdamOrmondroyd/PolyChordLite that referenced this pull request Nov 24, 2025
…hord#125)

* Refactor C/Fortran interfaces and enforce non-executable stack

• Added the linker flag "-Wl,-z,noexecstack" in Makefile_gnu to disable executable stacks for improved security.
• In src/polychord/interfaces.F90:
move all functions defined internally in contains functions to
module-level definitions with module-level variables.

This fixes the bug found in PolyChord#124 which has arisen for glibc 2.41 which
does not allow executable stack calls

* Fix maximiser.F90 nested function causing segfaults on Arch Linux

- Moved nested func() from do_maximisation contains section to module-level maximisation_func()
- Added module-level variables (func_settings, func_posterior, stored_loglikelihood, stored_prior)
- Used procedure pointers with save attribute to maintain function context
- Completes fix for Issue PolyChord#124 alongside interfaces.F90 changes
- Eliminates all nested functions that cause executable stack requirements with glibc 2.41+

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

* Bump version to 1.22.2

Version 1.22.2 includes:
- Fixed maximiser segfaults on Arch Linux (glibc 2.41+) by eliminating nested functions
- Fixed Fortran write statement comma formatting issues
- Added Python 3.12 support and updated CI to test Python 3.8-3.12
- Complete Arch Linux compatibility for modern systems

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
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