From a755b80057e985468f477b13da6a7a414eb45ff4 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 1 Jan 2020 14:21:28 -0500 Subject: [PATCH] Demos: Link our normal startfiles into the dynamic lib demo Now that gcc knows about crtbeginS and crtendS, and knows not to link crt0.o into shared objects, we can get rid of the hacks required due to --nostartfiles. --- Demos/DynamicLink/LinkLib/DynamicLib.cpp | 8 ++------ Demos/DynamicLink/LinkLib/Makefile | 5 +---- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Demos/DynamicLink/LinkLib/DynamicLib.cpp b/Demos/DynamicLink/LinkLib/DynamicLib.cpp index 106eeb73a4..481cda0f58 100644 --- a/Demos/DynamicLink/LinkLib/DynamicLib.cpp +++ b/Demos/DynamicLink/LinkLib/DynamicLib.cpp @@ -3,14 +3,10 @@ #include #include -// FIXME: See Makefile. We need -ffreestanding and -nostartfiles to -// Get GCC to stop linking crt0.o w/our .so. -// So, we need __dso_handle. ... Yikes -extern void* __dso_handle __attribute__((__section__(".sdata"))); -extern void* __dso_handle __attribute__((__visibility__("hidden"))); -void* __dso_handle = (void*)1234; // FIXME: Is the dynamic linker supposed to set this value? // FIXME: Things defined in crt0 >:( +// We need to figure out a better way to get these symbols defined and available +// Even if we're linking a shared object. __thread int errno; char* __static_environ[] = { nullptr }; // We don't get the environment without some libc workarounds.. char** environ = __static_environ; diff --git a/Demos/DynamicLink/LinkLib/Makefile b/Demos/DynamicLink/LinkLib/Makefile index daac238c4e..80abed2882 100644 --- a/Demos/DynamicLink/LinkLib/Makefile +++ b/Demos/DynamicLink/LinkLib/Makefile @@ -11,8 +11,5 @@ all: $(DYNLIBRARY) DynamicLib.o: DynamicLib.cpp $(CXX) -DDEBUG -fPIC -isystem../../../ -o $@ -c $< -# FIXME: Why do I need -nostartfiles and -nofreestanding? -# GCC isn't smart enough to not link crt0 against this dynamic lib -# which is clearly wrong. Isn't it? We don't want _start... $(DYNLIBRARY): DynamicLib.o - $(CXX) -shared -nostartfiles -ffreestanding -o $(DYNLIBRARY) $< + $(CXX) -shared -o $(DYNLIBRARY) $<