aboutsummaryrefslogtreecommitdiffstats
path: root/src/ortho/mcode/binary_file.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2018-11-19 20:56:58 +0100
committerTristan Gingold <tgingold@free.fr>2018-11-19 20:56:58 +0100
commit8c63e8e316e9ab84931bc52eba002d56c14922a5 (patch)
treeeb7a23528354a2a1f653b5b6f0e756c503c2215f /src/ortho/mcode/binary_file.adb
parentfef22520072c40329a5e61559a723666748c7a0e (diff)
downloadghdl-8c63e8e316e9ab84931bc52eba002d56c14922a5.tar.gz
ghdl-8c63e8e316e9ab84931bc52eba002d56c14922a5.tar.bz2
ghdl-8c63e8e316e9ab84931bc52eba002d56c14922a5.zip
binary_file: add overflow detection for relocs.
Diffstat (limited to 'src/ortho/mcode/binary_file.adb')
-rw-r--r--src/ortho/mcode/binary_file.adb16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/ortho/mcode/binary_file.adb b/src/ortho/mcode/binary_file.adb
index d666a6626..ff675c490 100644
--- a/src/ortho/mcode/binary_file.adb
+++ b/src/ortho/mcode/binary_file.adb
@@ -519,11 +519,19 @@ package body Binary_File is
end case;
end Gen_Data_32;
- function To_Unsigned_32 (Off : Pc_Type) return Unsigned_32 is
+ function To_Unsigned_32 (Off : Pc_Type) return Unsigned_32
+ is
+ Hi : Pc_Type;
+
+ function Shift_Right_Arithmetic (Op : Pc_Type; Amount : Natural)
+ return Pc_Type;
+ pragma Import (Intrinsic, Shift_Right_Arithmetic);
begin
- -- if Off >= 16#8000_0000# and Off < 16#ffff_ffff_8000_0000# then
- -- raise Constraint_Error;
- -- end if;
+ -- Check for overflow.
+ Hi := Shift_Right_Arithmetic (Off, 31) and 16#ffff_ffff#;
+ if Hi /= 0 and Hi /= 16#ffff_ffff# then
+ raise Constraint_Error;
+ end if;
return Unsigned_32 (Off and 16#ffff_ffff#);
end To_Unsigned_32;