Skip to content

Commit 315a4d3

Browse files
committed
build: fix ASLR for bitcoin-cli on Windows
ASLR is not currently working for the bitcoin-cli.exe binary. This is due to it not having a .reloc section, which is stripped by default by the mingw-w64 ld we use for gitian builds. A good summary of issues with ld and mingw-w64 is available in this thread: https://sourceware.org/bugzilla/show_bug.cgi?id=19011. All other Windows binaries that we distribute (bitcoind, bitcoin-qt, bitcoin-wallet, bitcoin-tx and test_bitcoin) do not suffer this issue, and currently having working ASLR. This is due to them exporting (inadvertent or not) libsecp256k1 symbols, and, as a result, the .reloc section is not stripped by ld. This change is a temporary workaround, also the same one described here: https://www.kb.cert.org/vuls/id/307144/, that causes main() to be exported. Exporting a symbol will mean that the .reloc section is not stripped, and ASLR will function correctly.
1 parent 6ae99aa commit 315a4d3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/bitcoin-cli.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,19 @@ static int CommandLineRPC(int argc, char *argv[])
551551
return nRet;
552552
}
553553

554-
int main(int argc, char* argv[])
555-
{
556554
#ifdef WIN32
555+
// Export main() and ensure working ASLR on Windows.
556+
// Exporting a symbol will prevent the linker from stripping
557+
// the .reloc section from the binary, which is a requirement
558+
// for ASLR. This is a temporary workaround until a fixed
559+
// version of binutils is used for releases.
560+
__declspec(dllexport) int main(int argc, char* argv[])
561+
{
557562
util::WinCmdLineArgs winArgs;
558563
std::tie(argc, argv) = winArgs.get();
564+
#else
565+
int main(int argc, char* argv[])
566+
{
559567
#endif
560568
SetupEnvironment();
561569
if (!SetupNetworking()) {

0 commit comments

Comments
 (0)