Skip to content

Commit

Permalink
fix Issue 13939 - IASM shouldn't access global symbol with PIC code
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jan 6, 2015
1 parent 83bf7e5 commit c9a383c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 41 deletions.
2 changes: 2 additions & 0 deletions src/iasm.c
Expand Up @@ -2366,6 +2366,8 @@ static void asm_merge_symbol(OPND *o1, Dsymbol *s)
}
if (v->isThreadlocal())
error(asmstate.loc, "cannot directly load TLS variable '%s'", v->toChars());
else if (v->isDataseg() && global.params.pic)
error(asmstate.loc, "cannot directly load global variable '%s' with PIC code", v->toChars());
}
em = s->isEnumMember();
if (em)
Expand Down
8 changes: 8 additions & 0 deletions test/Makefile
Expand Up @@ -118,8 +118,13 @@ DISABLED_TESTS += dhry
# runnable/dhry.d(488): Error: undefined identifier dtime
endif

ifeq ($(OS),win32)
DISABLED_FAIL_TESTS += fail13939
endif

ifeq ($(OS),win64)
DISABLED_TESTS += testxmm
DISABLED_FAIL_TESTS += fail13939
endif

ifeq ($(OS),osx)
Expand Down Expand Up @@ -159,6 +164,9 @@ $(RESULTS_DIR)/compilable/%.sh.out: compilable/%.sh $(RESULTS_DIR)/.created $(RE
$(QUIET) echo " ... $(<D)/$*.sh"
$(QUIET) ./$(<D)/$*.sh

$(addsuffix .d.out,$(addprefix $(RESULTS_DIR)/fail_compilation/,$(DISABLED_FAIL_TESTS))): $(RESULTS_DIR)/.created
$(QUIET) echo " ... $@ - disabled"

$(RESULTS_DIR)/fail_compilation/%.d.out: fail_compilation/%.d $(RESULTS_DIR)/.created $(RESULTS_DIR)/d_do_test$(EXE) $(DMD)
$(QUIET) $(RESULTS_DIR)/d_do_test $(<D) $* d

Expand Down
16 changes: 16 additions & 0 deletions test/fail_compilation/fail13939.d
@@ -0,0 +1,16 @@
// REQUIRED_ARGS: -o- -fPIC
/*
TEST_OUTPUT:
---
fail_compilation/fail13939.d(14): Error: cannot directly load global variable 'val' with PIC code
---
*/
version(Windows) static assert(0);
void test1()
{
__gshared int val;
asm
{
mov EAX, val;
}
}
91 changes: 50 additions & 41 deletions test/runnable/s2ir.d
Expand Up @@ -4,17 +4,26 @@ import std.stdio;
/***********************************/

void test1()
{ int i;
{
int i;
__gshared int j;

version (D_InlineAsm_X86)
{
asm
{
naked ;
mov EAX, i ;
mov EAX, j ;
}
asm
{
naked ;
mov EAX, i ;
}
version(OSX)
{}
else
{
asm
{
mov EAX, j ;
}
}
}
}

Expand All @@ -24,8 +33,8 @@ int main()
{
for (int i = 0; ; i++)
{
if (i == 10)
break;
if (i == 10)
break;
}

string[] a = new string[3];
Expand All @@ -34,53 +43,53 @@ int main()
a[2] = "foo";

foreach (string s; a)
writefln(s);
writefln(s);

switch (1)
{
default:
break;
default:
break;
}

switch ("foo"w)
{
case "foo":
break;
default: assert(0);
case "foo":
break;
default: assert(0);
}

switch (1)
{
case 1:
try
{
goto default;
}
catch (Throwable o)
{
}
break;

default:
break;
case 1:
try
{
goto default;
}
catch (Throwable o)
{
}
break;

default:
break;
}

switch (1)
{
case 1:
try
{
goto case 2;
}
catch (Throwable o)
{
}
break;

case 2:
break;

default: assert(0);
case 1:
try
{
goto case 2;
}
catch (Throwable o)
{
}
break;

case 2:
break;

default: assert(0);
}

writefln("Success\n");
Expand Down

0 comments on commit c9a383c

Please sign in to comment.