From 10afa6944bb3ac479cbcabc5499a86136907b95f Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 5 Jan 2018 07:43:53 +0100 Subject: [PATCH 1/4] Fix issue 18193 - module config is in file 'rt/config.d' which cannot be read (edit) src/rt isn't shipped with druntime's imports, so it can't be imported directly from core.runtime. This PR fixes importing rt.config from a public druntime module by replacing it with an extern definition. To reproduce the bug create a file that imports 'core.runtime' and compile it with: dmd -unittest -deps filename.d The error is: /usr/include/dmd/druntime/import/core/runtime.d(653): Error: module config is in file 'rt/config.d' which cannot be read --- src/core/runtime.d | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/runtime.d b/src/core/runtime.d index ab995882e1..b9b3573293 100644 --- a/src/core/runtime.d +++ b/src/core/runtime.d @@ -650,13 +650,18 @@ extern (C) UnitTestResult runModuleUnitTests() } } } - import rt.config : rt_configOption; + + import core.internal.traits : externDFunc; + alias rt_configCallBack = string delegate(string) @nogc nothrow; + alias fn_configOption = string function(string opt, scope rt_configCallBack dg, bool reverse) @nogc nothrow; + alias rt_configOption = externDFunc!("rt.config.rt_configOption", fn_configOption); + if (results.passed != results.executed) { // by default, we always print a summary if there are failures. results.summarize = true; } - else switch (rt_configOption("testmode")) + else switch (rt_configOption("testmode", null, false)) { case "": // By default, run main. Switch to only doing unit tests in 2.080 @@ -674,7 +679,7 @@ extern (C) UnitTestResult runModuleUnitTests() results.summarize = !results.runMain; break; default: - throw new Error("Unknown --DRT-testmode option: " ~ rt_configOption("testmode")); + throw new Error("Unknown --DRT-testmode option: " ~ rt_configOption("testmode", null, false)); } return results; From 105d4a5ca279316665b3b796bf5ca7d249595caf Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 7 Jan 2018 20:42:44 +0100 Subject: [PATCH 2/4] Add test to the bug 18193 --- posix.mak | 2 +- test/imports/Makefile | 14 ++++++++++++++ test/imports/src/bug18193.d | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/imports/Makefile create mode 100644 test/imports/src/bug18193.d diff --git a/posix.mak b/posix.mak index b371bdaeed..698545bf53 100644 --- a/posix.mak +++ b/posix.mak @@ -231,7 +231,7 @@ UT_MODULES:=$(patsubst src/%.d,$(ROOT)/unittest/%,$(SRCS)) HAS_ADDITIONAL_TESTS:=$(shell test -d test && echo 1) ifeq ($(HAS_ADDITIONAL_TESTS),1) ADDITIONAL_TESTS:=test/init_fini test/exceptions test/coverage test/profile test/cycles test/allocations test/typeinfo \ - test/thread test/unittest + test/thread test/unittest test/imports ADDITIONAL_TESTS+=$(if $(SHARED),test/shared,) endif diff --git a/test/imports/Makefile b/test/imports/Makefile new file mode 100644 index 0000000000..03ec7b3b9a --- /dev/null +++ b/test/imports/Makefile @@ -0,0 +1,14 @@ +include ../common.mak + +TESTS:=bug18193 + +.PHONY: all clean +all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS))) + +$(ROOT)/%.done: + @echo Testing $* + @mkdir -p $(basename $@) + $(QUIET)$(DMD) -o- -deps=$@ -Isrc -I../../import src/$* + +clean: + rm -rf $(GENERATED) diff --git a/test/imports/src/bug18193.d b/test/imports/src/bug18193.d new file mode 100644 index 0000000000..157eb6c496 --- /dev/null +++ b/test/imports/src/bug18193.d @@ -0,0 +1 @@ +import core.runtime; From b38f88f22a264f2df5c7aabb66d1b63834db0ada Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Thu, 11 Jan 2018 19:35:35 +0100 Subject: [PATCH 3/4] Require druntime to be built before tests are run --- posix.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posix.mak b/posix.mak index 698545bf53..6678715d9e 100644 --- a/posix.mak +++ b/posix.mak @@ -241,7 +241,7 @@ unittest : $(UT_MODULES) $(addsuffix /.run,$(ADDITIONAL_TESTS)) @echo done else unittest : unittest-debug unittest-release -unittest-%: +unittest-%: target $(MAKE) -f $(MAKEFILE) unittest OS=$(OS) MODEL=$(MODEL) DMD=$(DMD) BUILD=$* endif From 515c9e2cbe2b9c4437c6d8dae1631373e3209663 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Tue, 9 Jan 2018 09:11:58 +0100 Subject: [PATCH 4/4] Fix rt.sections imports in core.thread --- src/core/thread.d | 21 +++++++++++++++------ test/imports/Makefile | 2 +- test/imports/src/bug18193.d | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/core/thread.d b/src/core/thread.d index f69defca35..6379e6c6bd 100644 --- a/src/core/thread.d +++ b/src/core/thread.d @@ -304,7 +304,6 @@ else version( Posix ) { version (Shared) { - import rt.sections; Thread obj = cast(Thread)(cast(void**)arg)[0]; auto loadedLibraries = (cast(void**)arg)[1]; .free(arg); @@ -317,7 +316,11 @@ else version( Posix ) // loadedLibraries need to be inherited from parent thread // before initilizing GC for TLS (rt_tlsgc_init) - version (Shared) inheritLoadedLibraries(loadedLibraries); + version (Shared) + { + externDFunc!("rt.sections_elf_shared.inheritLoadedLibraries", + void function(void*) @nogc nothrow)(loadedLibraries); + } assert( obj.m_curr is &obj.m_main ); obj.m_main.bstack = getStackBottom(); @@ -404,7 +407,11 @@ else version( Posix ) append( t ); } rt_moduleTlsDtor(); - version (Shared) cleanupLoadedLibraries(); + version (Shared) + { + externDFunc!("rt.sections_elf_shared.cleanupLoadedLibraries", + void function() @nogc nothrow)(); + } } catch( Throwable t ) { @@ -712,15 +719,17 @@ class Thread version (Shared) { - import rt.sections; - auto libs = pinLoadedLibraries(); + auto libs = externDFunc!("rt.sections_elf_shared.pinLoadedLibraries", + void* function() @nogc nothrow)(); + auto ps = cast(void**).malloc(2 * size_t.sizeof); if (ps is null) onOutOfMemoryError(); ps[0] = cast(void*)this; ps[1] = cast(void*)libs; if( pthread_create( &m_addr, &attr, &thread_entryPoint, ps ) != 0 ) { - unpinLoadedLibraries(libs); + externDFunc!("rt.sections_elf_shared.unpinLoadedLibraries", + void function(void*) @nogc nothrow)(libs); .free(ps); onThreadError( "Error creating thread" ); } diff --git a/test/imports/Makefile b/test/imports/Makefile index 03ec7b3b9a..e4f6766888 100644 --- a/test/imports/Makefile +++ b/test/imports/Makefile @@ -8,7 +8,7 @@ all: $(addprefix $(ROOT)/,$(addsuffix .done,$(TESTS))) $(ROOT)/%.done: @echo Testing $* @mkdir -p $(basename $@) - $(QUIET)$(DMD) -o- -deps=$@ -Isrc -I../../import src/$* + $(QUIET)$(DMD) -version=Shared -o- -deps=$@ -Isrc -I../../import src/$* clean: rm -rf $(GENERATED) diff --git a/test/imports/src/bug18193.d b/test/imports/src/bug18193.d index 157eb6c496..bd3fd521d0 100644 --- a/test/imports/src/bug18193.d +++ b/test/imports/src/bug18193.d @@ -1 +1,2 @@ import core.runtime; +import core.thread;