5 # Check NASM map output for overflow
7 # This assumes that a section for which start != vstart, both
8 # ranges need to be checked for overflow (true for SYSLINUX)
11 ($in, $target) = @ARGV;
14 my($s1,$e1,$s2,$e2) = @_;
16 return 1 if ( $s2 < $e1 && $e2 > $s1 );
17 return 1 if ( $s1 < $e2 && $e1 > $s2 );
22 open(IN
, '<', $in) or die "$0: Cannot open input file: $in\n";
25 while ( $line = <IN
> ) {
26 if ( $line =~ /^-/ ) {
27 if ( $line =~ /^\-\-\-\- Section (\S+) / ) {
32 } elsif ( defined($section) ) {
33 if ( $line =~ /^length\:\s*(\S+)/ ) {
34 $length{$section} = hex $1;
35 } elsif ( $line =~ /^start\:\s*(\S+)/ ) {
36 $start{$section} = hex $1;
37 } elsif ( $line =~ /^vstart\:\s*(\S+)/ ) {
38 $vstart{$section} = hex $1;
46 foreach $s ( keys(%start) ) {
48 $svstart = $vstart{$s};
49 $send = $sstart + $length{$s};
50 $svend = $svstart + $length{$s};
52 if ( $send > 0x10000 || $svend > 0x10000 ) {
53 print STDERR
"$target: 16-bit overflow on section $s\n";
57 foreach $o ( keys(%start) ) {
61 $ovstart = $vstart{$o};
62 $oend = $ostart + $length{$o};
63 $ovend = $ovstart + $length{$o};
65 if ( overlap
($sstart, $send, $ostart, $oend) ||
66 overlap
($svstart, $svend, $ostart, $oend) ||
67 overlap
($sstart, $send, $ovstart, $ovend) ||
68 overlap
($svstart, $svend, $ovstart, $ovend) ) {
69 print STDERR
"$target: section $s overlaps section $o\n";