Fix Issue 24168 - Corrupted if TLS values are passed in ref parameters (#15705)

when compiling with -fPIE
This commit is contained in:
Hiroki Noda 2023-10-20 15:04:44 +09:00 committed by GitHub
parent 0acee0c8a7
commit c2cab2c54f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 8 deletions

View file

@ -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:

View 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());
}