Skip to content

[libc] Add Scrt1.o to startup_components #97497

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

izaakschroeder
Copy link
Contributor

@izaakschroeder izaakschroeder commented Jul 3, 2024

Needed for -fpie targets. Don't know if this is safe or not... but it seems to run compiled C++ executables.

Needs for `-fpie` targets. Don't know if this is safe or not... but it seems to run compiled executables.
@izaakschroeder izaakschroeder mentioned this pull request Jul 3, 2024
39 tasks
@llvmbot llvmbot added the libc label Jul 3, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 3, 2024

@llvm/pr-subscribers-libc

Author: Izaak Schroeder (izaakschroeder)

Changes

Needs for -fpie targets. Don't know if this is safe or not... but it seems to run compiled executables.


Full diff: https://github.com/llvm/llvm-project/pull/97497.diff

1 Files Affected:

  • (modified) libc/startup/linux/CMakeLists.txt (+10-1)
diff --git a/libc/startup/linux/CMakeLists.txt b/libc/startup/linux/CMakeLists.txt
index 336c5d0f6bfa2..b721d15091227 100644
--- a/libc/startup/linux/CMakeLists.txt
+++ b/libc/startup/linux/CMakeLists.txt
@@ -118,6 +118,15 @@ merge_relocatable_object(
   .do_start
 )
 
+# HACK: Is this even ok?
+# For reference: `Scrt1` is used when `-fpie` vs `crt1` for `-fno-pie`
+merge_relocatable_object(
+  Scrt1
+  .${LIBC_TARGET_ARCHITECTURE}.start
+  .${LIBC_TARGET_ARCHITECTURE}.tls
+  .do_start
+)
+
 add_startup_object(
   crti
   SRC
@@ -131,7 +140,7 @@ add_startup_object(
 )
 
 add_custom_target(libc-startup)
-set(startup_components crt1 crti crtn)
+set(startup_components Scrt1 crt1 crti crtn)
 foreach(target IN LISTS startup_components)
   set(fq_target_name libc.startup.linux.${target})
   add_dependencies(libc-startup ${fq_target_name})

@izaakschroeder
Copy link
Contributor Author

izaakschroeder commented Jul 3, 2024

@SchrodingerZhu
Copy link
Contributor

cc @MaskRay . I am not sure directly creating crt1 to Scrt1 based on crt1 will work? If it does work for current configuration, it can be easily broken in the future. -pie, -static, -static-pie should have different relocation policies.

@izaakschroeder
Copy link
Contributor Author

@SchrodingerZhu @MaskRay is there a simple path forward I can take, even if temporarily, to keep the ball moving? Like adding a .start-pie / .tls-pie (based on .start and .tls respectively) or something that is a copy but that could easily be modified in the future?

@MaskRay
Copy link
Member

MaskRay commented Jul 3, 2024

cc @MaskRay . I am not sure directly creating crt1 to Scrt1 based on crt1 will work? If it does work for current configuration, it can be easily broken in the future. -pie, -static, -static-pie should have different relocation policies.

I am not familiar with the build system, but you can create Scrt1.o and make crt1.o a symlink.
For -static-pie, rcrt1.o is needed and it needs to resolve relative relocations (also IRELATIVE if ifunc is supported).

@jhuber6
Copy link
Contributor

jhuber6 commented Jul 3, 2024

cc @MaskRay . I am not sure directly creating crt1 to Scrt1 based on crt1 will work? If it does work for current configuration, it can be easily broken in the future. -pie, -static, -static-pie should have different relocation policies.

I am not familiar with the build system, but you can create Scrt1.o and make crt1.o a symlink. For -static-pie, rcrt1.o is needed and it needs to resolve relative relocations (also IRELATIVE if ifunc is supported).

Do you know where the differences between these files is documented?

@MaskRay
Copy link
Member

MaskRay commented Jul 3, 2024

cc @MaskRay . I am not sure directly creating crt1 to Scrt1 based on crt1 will work? If it does work for current configuration, it can be easily broken in the future. -pie, -static, -static-pie should have different relocation policies.

I am not familiar with the build system, but you can create Scrt1.o and make crt1.o a symlink. For -static-pie, rcrt1.o is needed and it needs to resolve relative relocations (also IRELATIVE if ifunc is supported).

Do you know where the differences between these files is documented?

They are undocumented. One needs to investigate whether other libc implementations do...

@jhuber6
Copy link
Contributor

jhuber6 commented Jul 3, 2024

They are undocumented. One needs to investigate whether other libc implementations do...

Good to know my failing to find anything online wasn't a skill issue, thanks.

Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

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

Throwing a "minus one" on this for now until we better understand if/why this is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants