Repository navigation
We need a slice of Codon PIE #874
Charles-Kaminski
started this conversation in
General
Replies: 2 comments 3 replies
|
We'll look into adding this in the next release, @Charles-Kaminski -- thanks for bringing it up! |
1 reply
|
@arshajii You might also want to take a quick look at https://github.com/orgs/unikraft/discussions/1945. The discussion focuses on what Unikraft could do on its end to support Codon. I'd be interested in hearing your thoughts on my suggestions to the Unikraft team. Specifically, I propose a change to their compatibility layer that would allow Codon's garbage collector to work on Unikraft running under KVM. I'm also hoping that any comments you add to the thread might help bring more visibility to the discussion within the Unikraft team. |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
I'd like to request explicit support for building position-independent executables (PIE) with Codon.
Codon currently appears to deliberately disable PIE linking for executables, even when the user supplies
-piethrough-linker-flags.This behavior is understandable given the existing implementation, but it prevents users from selecting PIE for environments that require or benefit from position-independent executables.
I encountered this while developing a Codon HTTP server prototype running on Unikraft under QEMU/KVM to see if Codon could be supported in this environment.
Using a custom compiler wrapper, I was able to successfully build and execute the application as PIE so long as I also supported --relocation-model=pic in the tool chain.
Current Implementation
In Codon's source code,
codon/cir/llvm/llvisitor.cpp, the executable linking process explicitly appends-no-pieafter user-supplied linker flags.Relevant source:
https://github.com/exaloop/codon/blob/3aca1a7d/codon/cir/llvm/llvisitor.cpp#L3157-L3186
The comment indicates that
-no-piewas introduced to avoid relocation errors when linking non-position-independent object code on systems where GCC defaults to PIE.Additionally, the object-generation path contains:
This suggests that ordinary executables are generated without PIC by default, while libraries use position-independent code.
Consequently, supporting PIE properly should involve both object-code generation and linker configuration.
Motivation and Justification
PIE support would improve Codon's suitability for modern Linux deployments and systems-oriented applications.
Benefits include:
In my case, Unikraft's Linux binary compatibility environment required a PIE executable.
After working around Codon's linker behavior, I successfully compiled and ran a Codon HTTP server on Unikraft.
Steps to Reproduce
Tested with Codon 0.20.3 on Ubuntu Linux (x86_64).
Create a minimal Codon application:
Attempt to compile it as PIE:
codon build -release \ --relocation-model=pic \ -linker-flags="-pie" \ -o hello hello.pyInspect the executable:
Actual Behavior
Codon appends
-no-pieafter the user-supplied-pieoption.The resulting executable is non-PIE:
Expected Behavior
When explicitly requesting PIE, Codon should generate position-independent object code and link it as a PIE executable.
The resulting executable should report:
Ideally, the dynamic section should also contain:
Proposed Enhancement
Add explicit support for generating PIE executables.
Ideally, this would:
--pie, or through existing linker options.-pieto the linker without subsequently appending-no-pie.For example:
Alternatively, the existing command could be supported:
codon build -release \ --relocation-model=pic \ -linker-flags="-pie" \ -o hello hello.pyThe important requirement is that the compiler consistently configure both code generation and linking for PIE.
Thank you!
All reactions