You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnmain(){println!("Hello from main!");foo1();foo2();}#[link_section = "__TEXT,__foo1"]fnfoo1(){println!("Hello from foo1 in __TEXT!")}#[link_section = "__TEXT2,__foo2"]fnfoo2(){println!("Hello from foo2 in __TEXT2!");}
I expected to see this happen: all three functions are executed and their statements printed.
Instead, this happened:
Hello from main!
Hello from foo1 in __TEXT!
zsh: bus error ./t
In Console.app: Data/Stack execution not permitted: t[pid ___] at virtual address 0x108dde000, protections were read-write
foo1 works because it is located in the __TEXT segment, which is necessarily assigned rx permissions. foo2 does not, because the linker by default assigns rw permissions to new segments, which means that code cannot be executed from these segments.
I realize that this is may not be a proper bug (link_section is unsafe now). However, it is still problematic that new segments can only have the default rw permissions, when a user might want one to contain executable code or read-only data.
My current solution is to use -segprot in a build script's link arguments, but this only works on the root crate (rust-lang/cargo#9554).
Having an attribute or other transitive method of assigning segment permissions on mach-o targets is therefore necessary for the link_section attribute to be usable.
The text was updated successfully, but these errors were encountered:
I tried this code:
I expected to see this happen: all three functions are executed and their statements printed.
Instead, this happened:
In Console.app:
Data/Stack execution not permitted: t[pid ___] at virtual address 0x108dde000, protections were read-write
foo1 works because it is located in the
__TEXT
segment, which is necessarily assignedrx
permissions. foo2 does not, because the linker by default assignsrw
permissions to new segments, which means that code cannot be executed from these segments.Meta
rustc --version --verbose
:I realize that this is may not be a proper bug (
link_section
is unsafe now). However, it is still problematic that new segments can only have the defaultrw
permissions, when a user might want one to contain executable code or read-only data.My current solution is to use
-segprot
in a build script's link arguments, but this only works on the root crate (rust-lang/cargo#9554).Having an attribute or other transitive method of assigning segment permissions on mach-o targets is therefore necessary for the
link_section
attribute to be usable.The text was updated successfully, but these errors were encountered: