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.
This commit is contained in:
Andrew Kaster 2020-01-01 14:21:28 -05:00 committed by Andreas Kling
parent 2979491512
commit a755b80057
Notes: sideshowbarker 2024-07-19 10:27:41 +09:00
2 changed files with 3 additions and 10 deletions

View File

@ -3,14 +3,10 @@
#include <assert.h>
#include <stdio.h>
// 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;

View File

@ -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) $<