mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 05:00:16 +03:00
Fix Issue 24168 - Corrupted if TLS values are passed in ref parameters (#15705)
when compiling with -fPIE
This commit is contained in:
parent
0acee0c8a7
commit
c2cab2c54f
2 changed files with 55 additions and 8 deletions
|
@ -46,12 +46,26 @@ elem * el_var(Symbol *s)
|
|||
if (config.exe & EX_posix)
|
||||
{
|
||||
if (config.flags3 & CFG3pie &&
|
||||
s.Stype.Tty & mTYthread)
|
||||
return el_pievar(s); // Position Independent Executable
|
||||
s.Stype.Tty & mTYthread &&
|
||||
(s.Sclass == SC.global ||
|
||||
s.Sclass == SC.static_ ||
|
||||
s.Sclass == SC.locstat))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if (config.flags3 & CFG3pie &&
|
||||
s.Stype.Tty & mTYthread)
|
||||
{
|
||||
return el_pievar(s); // Position Independent Executable
|
||||
}
|
||||
|
||||
if (config.flags3 & CFG3pic &&
|
||||
!tyfunc(s.ty()))
|
||||
return el_picvar(s); // Position Independent Code
|
||||
if (config.flags3 & CFG3pic &&
|
||||
!tyfunc(s.ty()))
|
||||
{
|
||||
return el_picvar(s); // Position Independent Code
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config.exe & (EX_OSX | EX_OSX64))
|
||||
|
@ -128,7 +142,9 @@ else if (config.exe & EX_posix)
|
|||
Obj.refGOTsym();
|
||||
elem *e1 = el_calloc();
|
||||
e1.EV.Vsym = s;
|
||||
if (s.Sclass == SC.static_ || s.Sclass == SC.locstat)
|
||||
if (s.Sclass == SC.global ||
|
||||
s.Sclass == SC.static_ ||
|
||||
s.Sclass == SC.locstat)
|
||||
{
|
||||
e1.Eoper = OPrelconst;
|
||||
e1.Ety = TYnptr;
|
||||
|
@ -739,7 +755,7 @@ private elem *el_pievar(Symbol *s)
|
|||
case SC.static_:
|
||||
case SC.locstat:
|
||||
case SC.global:
|
||||
break;
|
||||
assert(0);
|
||||
|
||||
case SC.comdat:
|
||||
case SC.comdef:
|
||||
|
@ -767,7 +783,7 @@ private elem *el_pievar(Symbol *s)
|
|||
case SC.static_:
|
||||
case SC.locstat:
|
||||
case SC.global:
|
||||
break;
|
||||
assert(0);
|
||||
|
||||
case SC.comdat:
|
||||
case SC.comdef:
|
||||
|
|
31
compiler/test/runnable/issue24168.d
Normal file
31
compiler/test/runnable/issue24168.d
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
REQUIRED_ARGS: -fPIE
|
||||
DISABLED: win32 win64
|
||||
*/
|
||||
|
||||
//https://issues.dlang.org/show_bug.cgi?id=24168
|
||||
|
||||
int i = 42;
|
||||
|
||||
bool foo(ref int a)
|
||||
{
|
||||
return a == 42;
|
||||
}
|
||||
|
||||
ref int bar()
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
bool baz()
|
||||
{
|
||||
static int i = 42;
|
||||
return foo(i);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
assert(foo(i));
|
||||
assert(bar() == 42);
|
||||
assert(baz());
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue