<?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>126703</bug_id>
          
          <creation_ts>2014-01-09 08:34:15 -0800</creation_ts>
          <short_desc>Fix alignment in data section allocator.</short_desc>
          <delta_ts>2014-01-13 08:15:30 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <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="Peter Molnar">pmolnar.u-szeged</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>fpizlo</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>965916</commentid>
    <comment_count>0</comment_count>
    <who name="Peter Molnar">pmolnar.u-szeged</who>
    <bug_when>2014-01-09 08:34:15 -0800</bug_when>
    <thetext>Fix alignment in data section allocator.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>965917</commentid>
    <comment_count>1</comment_count>
      <attachid>220741</attachid>
    <who name="Peter Molnar">pmolnar.u-szeged</who>
    <bug_when>2014-01-09 08:36:01 -0800</bug_when>
    <thetext>Created attachment 220741
patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>965937</commentid>
    <comment_count>2</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2014-01-09 09:13:10 -0800</bug_when>
    <thetext>This doesn&apos;t actually fix any bugs. Your new code still fails to align allocations to the requested alignment except if that alignment is LSectionWord. You so removed the assertion to that effect so this patch is just a pure regression.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>966384</commentid>
    <comment_count>3</comment_count>
    <who name="Peter Molnar">pmolnar.u-szeged</who>
    <bug_when>2014-01-10 08:56:22 -0800</bug_when>
    <thetext>I got into this one when trying to allocate with alignment of 16. In this case, both the old, and the suggested new version allocates 2 LSectionWords, so in this case the code works OK, but the assertion is triggered.
 
But, suppose we wanted to allocate 15 or 17 with alignment of 16.
 
In case of 15, both calculations yield 2 LSectionWords, which is good, but in case of 17, the old one yields 3 LSectionWords, which is not aligned to 16, but the suggested new calculation yields 4 LSectionWords which is the correct version I think.
 
It can&apos;t see why the new code &quot;fails to align allocations to the requested alignment except if that alignment is LSectionWord&quot;. Can you please explain this, or give an example?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>966754</commentid>
    <comment_count>4</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2014-01-10 22:25:48 -0800</bug_when>
    <thetext>(In reply to comment #3)
&gt; I got into this one when trying to allocate with alignment of 16. In this case, both the old, and the suggested new version allocates 2 LSectionWords, so in this case the code works OK, but the assertion is triggered.

Right, because there is no guarantee that the returned pointer is actually 16 byte aligned. That&apos;s what the assertion is asserting. It has nothing to do with allocation size. 

&gt; 
&gt; But, suppose we wanted to allocate 15 or 17 with alignment of 16.
&gt; 
&gt; In case of 15, both calculations yield 2 LSectionWords, which is good, but in case of 17, the old one yields 3 LSectionWords, which is not aligned to 16, but the suggested new calculation yields 4 LSectionWords which is the correct version I think.

Nobody castes if you allocate the right number of section words. The relevant part is the alignment of the returned pointer.

&gt; 
&gt; It can&apos;t see why the new code &quot;fails to align allocations to the requested alignment except if that alignment is LSectionWord&quot;. Can you please explain this, or give an example?

Do you understand how memory allocation works?  The OS allocator, or the language allocator like C++ &quot;new&quot;, will provide a hard guarantee that the returned pointer is aligned to some machine word amount. We conservatively assume that it&apos;s sizeof(LSectionWord). The OS allocator isn&apos;t going to magically align allocations to the thing that LLVM wanted via the &quot;alignment&quot; parameter. We just asset that LLVM will never ask for alignment greater than sizeof(LSectionWord), which is true on Darwin.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>967314</commentid>
    <comment_count>5</comment_count>
    <who name="Peter Molnar">pmolnar.u-szeged</who>
    <bug_when>2014-01-13 07:52:52 -0800</bug_when>
    <thetext>(In reply to comment #4)
&gt; (In reply to comment #3)
&gt; &gt; I got into this one when trying to allocate with alignment of 16. In this case, both the old, and the suggested new version allocates 2 LSectionWords, so in this case the code works OK, but the assertion is triggered.
&gt; 
&gt; Right, because there is no guarantee that the returned pointer is actually 16 byte aligned. That&apos;s what the assertion is asserting. It has nothing to do with allocation size. 
&gt; 
&gt; &gt; 
&gt; &gt; But, suppose we wanted to allocate 15 or 17 with alignment of 16.
&gt; &gt; 
&gt; &gt; In case of 15, both calculations yield 2 LSectionWords, which is good, but in case of 17, the old one yields 3 LSectionWords, which is not aligned to 16, but the suggested new calculation yields 4 LSectionWords which is the correct version I think.
&gt; 
&gt; Nobody castes if you allocate the right number of section words. The relevant part is the alignment of the returned pointer.
&gt; 
&gt; &gt; 
&gt; &gt; It can&apos;t see why the new code &quot;fails to align allocations to the requested alignment except if that alignment is LSectionWord&quot;. Can you please explain this, or give an example?
&gt; 
&gt; Do you understand how memory allocation works?  The OS allocator, or the language allocator like C++ &quot;new&quot;, will provide a hard guarantee that the returned pointer is aligned to some machine word amount. We conservatively assume that it&apos;s sizeof(LSectionWord). The OS allocator isn&apos;t going to magically align allocations to the thing that LLVM wanted via the &quot;alignment&quot; parameter. We just asset that LLVM will never ask for alignment greater than sizeof(LSectionWord), which is true on Darwin.

Ok, I&apos;m getting your point now. It seems, on Linux, LLVM does ask for alignment greater than sizeof(LSectionWord), 16 bytes actually, when sizeof(LSectionWord) is 8 bytes, so in this case we can&apos;t have that assumption that we can have on Darwin.
Do you have any idea, how this could be handled to get in to work on Linux, without affecting Darwin?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>967321</commentid>
    <comment_count>6</comment_count>
    <who name="Filip Pizlo">fpizlo</who>
    <bug_when>2014-01-13 08:15:30 -0800</bug_when>
    <thetext>(In reply to comment #5)
&gt; (In reply to comment #4)
&gt; &gt; (In reply to comment #3)
&gt; &gt; &gt; I got into this one when trying to allocate with alignment of 16. In this case, both the old, and the suggested new version allocates 2 LSectionWords, so in this case the code works OK, but the assertion is triggered.
&gt; &gt; 
&gt; &gt; Right, because there is no guarantee that the returned pointer is actually 16 byte aligned. That&apos;s what the assertion is asserting. It has nothing to do with allocation size. 
&gt; &gt; 
&gt; &gt; &gt; 
&gt; &gt; &gt; But, suppose we wanted to allocate 15 or 17 with alignment of 16.
&gt; &gt; &gt; 
&gt; &gt; &gt; In case of 15, both calculations yield 2 LSectionWords, which is good, but in case of 17, the old one yields 3 LSectionWords, which is not aligned to 16, but the suggested new calculation yields 4 LSectionWords which is the correct version I think.
&gt; &gt; 
&gt; &gt; Nobody castes if you allocate the right number of section words. The relevant part is the alignment of the returned pointer.
&gt; &gt; 
&gt; &gt; &gt; 
&gt; &gt; &gt; It can&apos;t see why the new code &quot;fails to align allocations to the requested alignment except if that alignment is LSectionWord&quot;. Can you please explain this, or give an example?
&gt; &gt; 
&gt; &gt; Do you understand how memory allocation works?  The OS allocator, or the language allocator like C++ &quot;new&quot;, will provide a hard guarantee that the returned pointer is aligned to some machine word amount. We conservatively assume that it&apos;s sizeof(LSectionWord). The OS allocator isn&apos;t going to magically align allocations to the thing that LLVM wanted via the &quot;alignment&quot; parameter. We just asset that LLVM will never ask for alignment greater than sizeof(LSectionWord), which is true on Darwin.
&gt; 
&gt; Ok, I&apos;m getting your point now. It seems, on Linux, LLVM does ask for alignment greater than sizeof(LSectionWord), 16 bytes actually, when sizeof(LSectionWord) is 8 bytes, so in this case we can&apos;t have that assumption that we can have on Darwin.
&gt; Do you have any idea, how this could be handled to get in to work on Linux, without affecting Darwin?

man memalign</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>220741</attachid>
            <date>2014-01-09 08:36:01 -0800</date>
            <delta_ts>2014-01-09 09:12:06 -0800</delta_ts>
            <desc>patch</desc>
            <filename>ftl-allocator.patch</filename>
            <type>text/plain</type>
            <size>1662</size>
            <attacher name="Peter Molnar">pmolnar.u-szeged</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cgYi9Tb3VyY2UvSmF2
YVNjcmlwdENvcmUvQ2hhbmdlTG9nCmluZGV4IDM1ZmU4OTguLmQ5MzU2YTAgMTAwNjQ0Ci0tLSBh
L1NvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKKysrIGIvU291cmNlL0phdmFTY3JpcHRD
b3JlL0NoYW5nZUxvZwpAQCAtMSwzICsxLDE2IEBACisyMDE0LTAxLTA5ICBQZXRlciBNb2xuYXIg
IDxwbW9sbmFyLnUtc3plZ2VkQHBhcnRuZXIuc2Ftc3VuZy5jb20+CisKKyAgICAgICAgW0ZUTF0g
Rml4IGFsaWdubWVudCBpbiBkYXRhIHNlY3Rpb24gYWxsb2NhdG9yLgorICAgICAgICBodHRwczov
L2J1Z3Mud2Via2l0Lm9yZy9zaG93X2J1Zy5jZ2k/aWQ9MTI2NzAzCisKKyAgICAgICAgUmV2aWV3
ZWQgYnkgTk9CT0RZIChPT1BTISkuCisKKyAgICAgICAgKiBmdGwvRlRMQ29tcGlsZS5jcHA6Cisg
ICAgICAgIChKU0M6OkZUTDo6bW1BbGxvY2F0ZURhdGFTZWN0aW9uKToKKyAgICAgICAgVGhlIGNh
bGN1bGF0aW9uIG9mIHRoZSBzZWN0aW9uIHNpemUgb25seSB3b3JrZWQgcHJvcGVybHkgaWYgYWxp
Z25tZW50IHdhcyBsZX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v
bldvcmQ+IHNlY3Rpb24oCi0gICAgICAgIChzaXplICsgc2l6ZW9mKExTZWN0aW9uV29yZCkgLSAx
KSAvIHNpemVvZihMU2VjdGlvbldvcmQpKTsKKyAgICBSZWZDb3VudGVkQXJyYXk8TFNlY3Rpb25X
b3JkPiBzZWN0aW9uKFdURjo6cm91bmRVcFRvTXVsdGlwbGVPZihhbGlnbm1lbnQsIHNpemUpIC8g
c2l6ZW9mKExTZWN0aW9uV29yZCkpOwogICAgIAogICAgIGlmICghc3RyY21wKHNlY3Rpb25OYW1l
LCAiX19sbHZtX3N0YWNrbWFwcyIpKQogICAgICAgICBzdGF0ZS5zdGFja21hcHNTZWN0aW9uID0g
c2VjdGlvbjsK
</data>
<flag name="review"
          id="244512"
          type_id="1"
          status="-"
          setter="fpizlo"
    />
    <flag name="commit-queue"
          id="244513"
          type_id="3"
          status="-"
          setter="fpizlo"
    />
          </attachment>
      

    </bug>

</bugzilla>