Skip to content

Commit d8e718f

Browse files
committed
Merge branch 'mr/pietrek/make_sure_uwtables_are_emitted_on_windows' into 'master'
Mark functions with uwtable(default) attribute when SEH in use. See merge request eng/toolchain/gnat-llvm!369
2 parents b2b8539 + da536a9 commit d8e718f

File tree

6 files changed

+42
-0
lines changed

6 files changed

+42
-0
lines changed

llvm-interface/gnatllvm-codegen.adb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,10 @@ package body GNATLLVM.Codegen is
720720
Set_Module_PIC_PIE (Module, PIC_Level, PIE_Level);
721721
end if;
722722

723+
if SEH then
724+
Set_Unwind_Tables (Module);
725+
end if;
726+
723727
-- ??? Replace this by a parameter in system.ads or target.atp
724728

725729
if Target_Triple (TT_First .. TT_First + 3) = "wasm" then

llvm-interface/gnatllvm-glvalue.adb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,15 @@ package body GNATLLVM.GLValue is
18171817
Add_Named_Attribute (+V, Name, Value, Get_Global_Context);
18181818
end Add_Named_Attribute;
18191819

1820+
---------------------------
1821+
-- Add_Uwtable_Attribute --
1822+
---------------------------
1823+
1824+
procedure Add_Uwtable_Attribute (V : GL_Value) is
1825+
begin
1826+
Add_Uwtable_Attribute (+V);
1827+
end Add_Uwtable_Attribute;
1828+
18201829
------------------------
18211830
-- Add_Nest_Attribute --
18221831
------------------------

llvm-interface/gnatllvm-glvalue.ads

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,9 @@ package GNATLLVM.GLValue is
11711171
-- Add the appropropriate Inline attributes, if any, to the LLVM
11721172
-- function V based on the flags in Subp.
11731173

1174+
procedure Add_Uwtable_Attribute (V : GL_Value)
1175+
with Pre => Is_A_Function (V), Inline;
1176+
11741177
procedure Add_Named_Attribute (V : GL_Value; Name, Value : String)
11751178
with Pre => Is_A_Function (V), Inline;
11761179

llvm-interface/gnatllvm-subprograms.adb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,10 @@ package body GNATLLVM.Subprograms is
28542854

28552855
Add_Inline_Attribute (LLVM_Func, E);
28562856

2857+
if SEH then
2858+
Add_Uwtable_Attribute (LLVM_Func);
2859+
end if;
2860+
28572861
if No_Tail_Calls then
28582862
Add_Named_Attribute (LLVM_Func, "disable-tail-calls", "true");
28592863
end if;

llvm-interface/gnatllvm-wrapper.ads

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ package GNATLLVM.Wrapper is
150150
with Import, Convention => C,
151151
External_Name => "Add_No_Implicit_Float_Attribute";
152152

153+
procedure Add_Uwtable_Attribute (Func : Value_T)
154+
with Import, Convention => C,
155+
External_Name => "Add_Uwtable_Attribute";
156+
153157
function Has_Inline_Attribute (Func : Value_T) return Boolean
154158
with Pre => Present (Is_A_Function (Func));
155159

@@ -442,6 +446,10 @@ package GNATLLVM.Wrapper is
442446
(Module : Module_T; PIC : PIC_PIE_Level; PIE : PIC_PIE_Level)
443447
with Import, Convention => C, External_Name => "Set_Module_PIC_PIE";
444448

449+
procedure Set_Unwind_Tables
450+
(Module : Module_T)
451+
with Import, Convention => C, External_Name => "Set_Unwind_Tables";
452+
445453
function Has_Default_PIE (Triple : String) return Boolean;
446454

447455
function Has_SEH (Triple : String) return Boolean;

llvm-interface/llvm_wrapper.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ Add_Inline_No_Attribute (Function *fn)
159159
fn->addFnAttr (Attribute::NoInline);
160160
}
161161

162+
extern "C"
163+
void
164+
Add_Uwtable_Attribute (Function *fn)
165+
{
166+
fn->setUWTableKind(UWTableKind::Default);
167+
}
168+
162169
extern "C"
163170
void
164171
Add_Fn_Readonly_Attribute (Function *fn)
@@ -1196,6 +1203,13 @@ Set_Module_PIC_PIE (Module *M, int PIC, int PIE)
11961203
M->setPIELevel(static_cast<PIELevel::Level>(PIE));
11971204
}
11981205

1206+
extern "C"
1207+
void
1208+
Set_Unwind_Tables (Module *M)
1209+
{
1210+
M->setUwtable(UWTableKind::Default);
1211+
}
1212+
11991213
extern "C"
12001214
bool
12011215
Has_Default_PIE (const char *Target)

0 commit comments

Comments
 (0)