<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>183617</bug_id>
          
          <creation_ts>2018-03-13 15:47:23 -0700</creation_ts>
          <short_desc>[ARM] Build fails due to invalid cast on 32-bit targets</short_desc>
          <delta_ts>2018-04-10 20:26:44 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>bmalloc</component>
          <version>Other</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>183508</dup_id>
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Adrian Perez">aperez</reporter>
          <assigned_to name="Adrian Perez">aperez</assigned_to>
          <cc>ews-watchlist</cc>
    
    <cc>ggaren</cc>
    
    <cc>mark.lam</cc>
    
    <cc>mcatanzaro</cc>
    
    <cc>msaboff</cc>
    
    <cc>saam</cc>
    
    <cc>ysuzuki</cc>
    
    <cc>zan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1406269</commentid>
    <comment_count>0</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2018-03-13 15:47:23 -0700</bug_when>
    <thetext>While trying to update the WebKitGTK+ packaging in Buildroot to the
recent 2.20.0 release I&apos;ve found that the following prevents from
building for 32-bit ARM (more precisely, this was targeting ARMv7):

  In file included from ../../bmalloc/bmalloc/HeapKind.h:30:0,
                   from ../../bmalloc/bmalloc/ObjectType.h:30,
                   from ../../bmalloc/bmalloc/BumpAllocator.h:31,
                   from ../../bmalloc/bmalloc/Allocator.h:30,
                   from ../../bmalloc/bmalloc/Cache.h:29,
                   from ../../bmalloc/bmalloc/bmalloc.h:29,
                   from FastMalloc.cpp:246:
  ../../bmalloc/bmalloc/Gigacage.h: In function ‘Gigacage::BasePtrs&amp; Gigacage::basePtrs()’:
  ../../bmalloc/bmalloc/Gigacage.h:136:59: warning: cast from ‘char*’ to ‘Gigacage::BasePtrs*’ increases required alignment of target type [-Wcast-align]
       return *reinterpret_cast&lt;BasePtrs*&gt;(g_gigacageBasePtrs);
                                                             ^</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1406299</commentid>
    <comment_count>1</comment_count>
      <attachid>335746</attachid>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2018-03-13 17:04:43 -0700</bug_when>
    <thetext>Created attachment 335746
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1406300</commentid>
    <comment_count>2</comment_count>
    <who name="EWS Watchlist">ews-watchlist</who>
    <bug_when>2018-03-13 17:05:58 -0700</bug_when>
    <thetext>Attachment 335746 did not pass style-queue:


ERROR: Source/bmalloc/ChangeLog:3:  Please consider whether the use of security-sensitive phrasing could help someone exploit WebKit: invalid cast  [changelog/unwantedsecurityterms] [3]
Total errors found: 1 in 2 files


If any of these errors are false positives, please file a bug against check-webkit-style.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1406308</commentid>
    <comment_count>3</comment_count>
      <attachid>335746</attachid>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2018-03-13 17:27:01 -0700</bug_when>
    <thetext>Comment on attachment 335746
Patch

Surely this does not actually fix the alignment problem...?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1406314</commentid>
    <comment_count>4</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2018-03-13 17:47:27 -0700</bug_when>
    <thetext>(In reply to Michael Catanzaro from comment #3)
&gt; Comment on attachment 335746 [details]
&gt; Patch
&gt; 
&gt; Surely this does not actually fix the alignment problem...?

I had first:

   return *reinterpret_cast&lt;BasePtrs*&gt;(static_cast&lt;void*&gt;(g_gigacageBasePtrs));

but the simpler on seemed to work. I&apos;ll do one clean build, clearing
ccache, as today Carlos Lopez has found a footgun in Buildroot&apos;s ccache
handling and it could be that the build succeeded when it shouldn&apos;t.
I&apos;ll remove the cq+ in the meanwhile.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1406327</commentid>
    <comment_count>5</comment_count>
      <attachid>335746</attachid>
    <who name="EWS Watchlist">ews-watchlist</who>
    <bug_when>2018-03-13 18:19:52 -0700</bug_when>
    <thetext>Comment on attachment 335746
Patch

Attachment 335746 did not pass jsc-ews (mac):
Output: http://webkit-queues.webkit.org/results/6943489

New failing tests:
stress/ftl-put-by-id-setter-exception-interesting-live-state.js.dfg-eager-no-cjit-validate</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1406569</commentid>
    <comment_count>6</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2018-03-14 17:54:23 -0700</bug_when>
    <thetext>(In reply to Adrian Perez from comment #4)
&gt; (In reply to Michael Catanzaro from comment #3)
&gt; &gt; Comment on attachment 335746 [details]
&gt; &gt; Patch
&gt; &gt; 
&gt; &gt; Surely this does not actually fix the alignment problem...?
&gt; 
&gt; I had first:
&gt; 
&gt;    return
&gt; *reinterpret_cast&lt;BasePtrs*&gt;(static_cast&lt;void*&gt;(g_gigacageBasePtrs));
&gt; 
&gt; but the simpler on seemed to work. I&apos;ll do one clean build, clearing
&gt; ccache, as today Carlos Lopez has found a footgun in Buildroot&apos;s ccache
&gt; handling and it could be that the build succeeded when it shouldn&apos;t.
&gt; I&apos;ll remove the cq+ in the meanwhile.

Yep, it was a bad ccache case (╯°□°）╯︵ ┻━┻

I&apos;l re-upload the good version tomorrow.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1413161</commentid>
    <comment_count>7</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2018-04-09 20:49:14 -0700</bug_when>
    <thetext>*Poke.*</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1413176</commentid>
    <comment_count>8</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2018-04-09 21:37:55 -0700</bug_when>
    <thetext>(In reply to Adrian Perez from comment #0)
&gt; While trying to update the WebKitGTK+ packaging in Buildroot to the
&gt; recent 2.20.0 release I&apos;ve found that the following prevents from
&gt; building for 32-bit ARM (more precisely, this was targeting ARMv7):
&gt; 
&gt;   In file included from ../../bmalloc/bmalloc/HeapKind.h:30:0,
&gt;                    from ../../bmalloc/bmalloc/ObjectType.h:30,
&gt;                    from ../../bmalloc/bmalloc/BumpAllocator.h:31,
&gt;                    from ../../bmalloc/bmalloc/Allocator.h:30,
&gt;                    from ../../bmalloc/bmalloc/Cache.h:29,
&gt;                    from ../../bmalloc/bmalloc/bmalloc.h:29,
&gt;                    from FastMalloc.cpp:246:
&gt;   ../../bmalloc/bmalloc/Gigacage.h: In function ‘Gigacage::BasePtrs&amp;
&gt; Gigacage::basePtrs()’:
&gt;   ../../bmalloc/bmalloc/Gigacage.h:136:59: warning: cast from ‘char*’ to
&gt; ‘Gigacage::BasePtrs*’ increases required alignment of target type
&gt; [-Wcast-align]
&gt;        return *reinterpret_cast&lt;BasePtrs*&gt;(g_gigacageBasePtrs);
&gt;                                                              ^

Based on this, I&apos;m quite sure your fix is incorrect.  The definition of g_gigacageBasePtrs is as follows:

    extern &quot;C&quot; BEXPORT char g_gigacageBasePtrs[GIGACAGE_BASE_PTRS_SIZE] __attribute__((aligned(GIGACAGE_BASE_PTRS_SIZE)));

where ...

    #define GIGACAGE_BASE_PTRS_SIZE 4096

and ...

    struct BasePtrs {
        void* primitive;
        void* jsValue;
        void* string;
    };

That is: g_gigacageBasePtrs is expected to be aligned on a 4096 boundary.  Why would it increase alignment of the target type if we cast it to a BasePtrs* which points to a 12 byte type.  Hence, your real issue here is that your allocation of g_gigacageBasePtrs is not aligned on 4096 bytes.  Even if you silence the compiler warning, you&apos;re not fixing the real bug, and will get unexpected failures later during code execution.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1413178</commentid>
    <comment_count>9</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2018-04-09 21:43:27 -0700</bug_when>
    <thetext>(In reply to Mark Lam from comment #8)
&gt; Even if you silence the compiler warning, you&apos;re not fixing the real bug,
&gt; and will get unexpected failures later during code execution.

See protectGigacageBasePtrs() and unprotectGigacageBasePtrs().  The code expects to be able to mprotect g_gigacageBasePtrs.  If g_gigacageBasePtrs is not aligned on a page boundary, then you&apos;ll not get the behavior the code expects.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1413207</commentid>
    <comment_count>10</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2018-04-09 22:59:40 -0700</bug_when>
    <thetext>(In reply to Mark Lam from comment #8)
&gt; (In reply to Adrian Perez from comment #0)
&gt; &gt; While trying to update the WebKitGTK+ packaging in Buildroot to the
&gt; &gt; recent 2.20.0 release I&apos;ve found that the following prevents from
&gt; &gt; building for 32-bit ARM (more precisely, this was targeting ARMv7):
&gt; &gt; 
&gt; &gt;   In file included from ../../bmalloc/bmalloc/HeapKind.h:30:0,
&gt; &gt;                    from ../../bmalloc/bmalloc/ObjectType.h:30,
&gt; &gt;                    from ../../bmalloc/bmalloc/BumpAllocator.h:31,
&gt; &gt;                    from ../../bmalloc/bmalloc/Allocator.h:30,
&gt; &gt;                    from ../../bmalloc/bmalloc/Cache.h:29,
&gt; &gt;                    from ../../bmalloc/bmalloc/bmalloc.h:29,
&gt; &gt;                    from FastMalloc.cpp:246:
&gt; &gt;   ../../bmalloc/bmalloc/Gigacage.h: In function ‘Gigacage::BasePtrs&amp;
&gt; &gt; Gigacage::basePtrs()’:
&gt; &gt;   ../../bmalloc/bmalloc/Gigacage.h:136:59: warning: cast from ‘char*’ to
&gt; &gt; ‘Gigacage::BasePtrs*’ increases required alignment of target type
&gt; &gt; [-Wcast-align]
&gt; &gt;        return *reinterpret_cast&lt;BasePtrs*&gt;(g_gigacageBasePtrs);
&gt; &gt;                                                              ^
&gt; 
&gt; Based on this, I&apos;m quite sure your fix is incorrect.  The definition of
&gt; g_gigacageBasePtrs is as follows:
&gt; 
&gt;     extern &quot;C&quot; BEXPORT char g_gigacageBasePtrs[GIGACAGE_BASE_PTRS_SIZE]
&gt; __attribute__((aligned(GIGACAGE_BASE_PTRS_SIZE)));
&gt; 
&gt; where ...
&gt; 
&gt;     #define GIGACAGE_BASE_PTRS_SIZE 4096
&gt; 
&gt; and ...
&gt; 
&gt;     struct BasePtrs {
&gt;         void* primitive;
&gt;         void* jsValue;
&gt;         void* string;
&gt;     };
&gt; 
&gt; That is: g_gigacageBasePtrs is expected to be aligned on a 4096 boundary. 
&gt; Why would it increase alignment of the target type if we cast it to a
&gt; BasePtrs* which points to a 12 byte type.  Hence, your real issue here is
&gt; that your allocation of g_gigacageBasePtrs is not aligned on 4096 bytes. 
&gt; Even if you silence the compiler warning, you&apos;re not fixing the real bug,
&gt; and will get unexpected failures later during code execution.

Is it because g_gigacageBasePtrs are `char` array?
I think the compiler says alignment of `char` and `BasePtrs` are different.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1413473</commentid>
    <comment_count>11</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2018-04-10 17:22:45 -0700</bug_when>
    <thetext>In case it helps: I have made a build with a more recent WebKit
source and seems to work fine after r230380 was landed by Yusuke
for bug #18350. So maybe we can close this one as duplicate.

I had for a bit a patch with a double cast —to “void*”, then to
“BasePtrs*”— sitting on my lap for a bit, but I didn&apos;t manage to
wrap my head around why that works, and therefore decided to not
submit it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1413518</commentid>
    <comment_count>12</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2018-04-10 18:53:40 -0700</bug_when>
    <thetext>Sounds like this is fixed, if the build is no longer failing and the warning is gone?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1413539</commentid>
    <comment_count>13</comment_count>
    <who name="Mark Lam">mark.lam</who>
    <bug_when>2018-04-10 20:26:44 -0700</bug_when>
    <thetext>This was actually resolved by Yusuke&apos;s alignas patch which gave g_gigacageBasePtrs the alignment it needs.

*** This bug has been marked as a duplicate of bug 183508 ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>335746</attachid>
            <date>2018-03-13 17:04:43 -0700</date>
            <delta_ts>2018-04-09 21:38:04 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-183617-20180314020438.patch</filename>
            <type>text/plain</type>
            <size>1371</size>
            <attacher name="Adrian Perez">aperez</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjI5NTg4CmRpZmYgLS1naXQgYS9Tb3VyY2UvYm1hbGxvYy9D
aGFuZ2VMb2cgYi9Tb3VyY2UvYm1hbGxvYy9DaGFuZ2VMb2cKaW5kZXggMTNjYWQ2MWZjMDBkOTM3
Nzc0NTcxZDAxNDc0MTc1ZGI0ODZiZWE2Yi4uNzQxZTExYjMzNjBmYTkzZGQ1NzVkMmFiNzgyYWQ2
ZjllNjU3YjA0ZiAxMDA2NDQKLS0tIGEvU291cmNlL2JtYWxsb2MvQ2hhbmdlTG9nCisrKyBiL1Nv
dXJjZS9ibWFsbG9jL0NoYW5nZUxvZwpAQCAtMSwzICsxLDE2IEBACisyMDE4LTAzLTEzICBBZHJp
YW4gUGVyZXogZGUgQ2FzdHJvICA8YXBlcmV6QGlnYWxpYS5jb20+CisKKyAgICAgICAgW0FSTV0g
QnVpbGQgZmFpbHMgZHVlIHRvIGludmFsaWQgY2FzdCBvbiAzMi1iaXQgdGFyZ2V0cworICAgICAg
ICBodHRwczovL2J1Z3Mud2Via2l0Lm9yZy9zaG93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VybiAqcmVpbnRlcnByZXRfY2FzdDxCYXNlUHRycyo+KGdfZ2ln
YWNhZ2VCYXNlUHRycyk7CisgICAgcmV0dXJuIHJlaW50ZXJwcmV0X2Nhc3Q8QmFzZVB0cnMmPihn
X2dpZ2FjYWdlQmFzZVB0cnMpOwogfQogCiBCSU5MSU5FIHZvaWQqJiBiYXNlUHRyKEtpbmQga2lu
ZCkK
</data>
<flag name="review"
          id="354323"
          type_id="1"
          status="-"
          setter="mark.lam"
    />
    <flag name="commit-queue"
          id="354328"
          type_id="3"
          status="-"
          setter="ews-watchlist"
    />
          </attachment>
      

    </bug>

</bugzilla>