Skip to content
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

[MinGW] MinGW dynamicbase #74979

Closed
wants to merge 2 commits into from
Closed

Conversation

xu-chiheng
Copy link

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Dec 10, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Dec 10, 2023

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: 徐持恒 Xu Chiheng (xu-chiheng)

Changes

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

1 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/MinGW.cpp (+1)
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp
index 5d7f8675daf8d2..50181837d39399 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -165,6 +165,7 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
       CmdArgs.push_back("DllMainCRTStartup");
     CmdArgs.push_back("--enable-auto-image-base");
   }
+  CmdArgs.push_back("--dynamicbase");
 
   if (Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
     CmdArgs.push_back("--no-demangle");

Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

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

This is not necessary.

Since 514b4e191d5f46de8e142fe216e677a35fa9c4bb in binutils (https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=514b4e191d5f46de8e142fe216e677a35fa9c4bb), dynamicbase is enabled by default. Also since e72403f in llvm-project, LLD also does the same.

Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

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

No, you do not need to do this. There's no need to add --dynamicbase manually in Clang. As I already posted, both ld.bfd and ld.lld default to --dynamicbase enabled since 2020.

@xu-chiheng
Copy link
Author

Also

In Cygwin with binutils 2.41, --dynamicbase make a difference, so I thought MinGW also need it.

@mstorsjo
Copy link
Member

Also

In Cygwin with binutils 2.41, --dynamicbase make a difference, so I thought MinGW also need it.

No, MinGW does not need it, as it has been enabled by default since binutils 2.36.

Apparently that change, https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=514b4e191d5f46de8e142fe216e677a35fa9c4bb, didn't apply to Cygwin but only to MinGW. But if Cygwin works with dynamicbase (I think it might have issues with it but I'm not sure?) then perhaps binutils should be changed to enable dynamicbase by default there, instead of changing compilers to pass the option by default.

@xu-chiheng
Copy link
Author

In Cygwin with binutils 2.41, --dynamicbase make a difference, so I thought MinGW also need it.

No, MinGW does not need it, as it has been enabled by default since binutils 2.36.

Apparently that change, https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=514b4e191d5f46de8e142fe216e677a35fa9c4bb, didn't apply to Cygwin but only to MinGW. But if Cygwin works with dynamicbase (I think it might have issues with it but I'm not sure?) then perhaps binutils should be changed to enable dynamicbase by default there, instead of changing compilers to pass the option by default.

Cygwin GCC and Clang must use dynamicbase, otherwise, there are errors like :
0 [main] clang-17 1506 child_info_fork::abort: ??\D:\cygwin64-packages\clang\bin\cygclangLex-17git.dll: Loaded to different address: parent(0x16E0000) != child(0x5C12D0000)
clang++: error: unable to execute command: posix_spawn failed: Resource temporarily unavailable
0 [main] clang-17 1507 child_info_fork::abort: ??\D:\cygwin64-packages\clang\bin\cygLLVMRISCVCodeGen-17git.dll: Loaded to different address: parent(0xE60000) != child(0xEC0000)
clang++: error: unable to execute command: posix_spawn failed: Resource temporarily unavailable

@xu-chiheng xu-chiheng closed this Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants