Răsfoiți Sursa

* patch by Rika: Better Align()'s #2, resolves #39512

florian 3 ani în urmă
părinte
comite
e26b298885
1 a modificat fișierele cu 11 adăugiri și 12 ștergeri
  1. 11 12
      compiler/ogbase.pas

+ 11 - 12
compiler/ogbase.pas

@@ -780,28 +780,25 @@ implementation
 
 
     function align_aword(v:aword;a:longword):aword;
     function align_aword(v:aword;a:longword):aword;
       begin
       begin
-        if a<=1 then
-          result:=v
-        else
-          result:=((v+a-1) div a) * a;
+        if a>0 then
+          a:=a-1;
+        result:=(v+a) and aword(not aword(a));
       end;
       end;
 
 
 
 
     function align_qword(v:qword;a:longword):qword;
     function align_qword(v:qword;a:longword):qword;
       begin
       begin
-        if a<=1 then
-          result:=v
-        else
-          result:=((v+a-1) div a) * a;
+        if a>0 then
+          a:=a-1;
+        result:=(v+a) and qword(not qword(a));
       end;
       end;
 
 
 
 
     function align_objsecofs(v:TObjSectionOfs;a:longword):TObjSectionOfs;
     function align_objsecofs(v:TObjSectionOfs;a:longword):TObjSectionOfs;
       begin
       begin
-        if a<=1 then
-          result:=v
-        else
-          result:=((v+a-1) div a) * a;
+        if a>0 then
+          a:=a-1;
+        result:=(v+a) and TObjSectionOfs(not TObjSectionOfs(a));
       end;
       end;
 
 
 
 
@@ -989,6 +986,8 @@ implementation
 {$endif i8086}
 {$endif i8086}
         { Setting the secoptions allocates Data if needed }
         { Setting the secoptions allocates Data if needed }
         secoptions:=Aoptions;
         secoptions:=Aoptions;
+        if (Aalign and (Aalign-1))<>0 then
+          internalerror(2022010401); { alignment is not a power of two }
         secalign:=Aalign;
         secalign:=Aalign;
         secsymidx:=0;
         secsymidx:=0;
         { relocation }
         { relocation }