[llvm] r234299 - [RuntimeDyld] Always allocate at least 1 byte for object sections in the JIT to
Lang Hames
lhames at gmail.com
Tue Apr 7 11:52:06 PDT 2015
Actually that was lazy thinking on my part - I didn't follow an
allocate.*Section call all the way to the bottom. I just assumed it was
mallocing, but it's probably using a bump-ptr allocator. Arguably we should
have an assertion for zero-sized allocations in our bump-ptr allocators to
catch zero-sized allocs - I can't think of any situation where they're
useful.
This fix is required either way, though it may be on the conservative side.
If I can convince myself that zero-sized sections don't need unique
addresses (which is almost certainly true) then we can just assign null for
them rather than calling allocate.*Section.
- Lang.
p.s. In case you're curious, I dug up the relevant malloc rule: "If the
size of the space requested is 0, the behavior is implementation-defined:
the value returned shall be either a null pointer or a unique pointer".
That's almost consistent with new char[0], but not quite, since it sounds
like the new can't return null. It's not consistent with the behavior I was
seeing, which was non-unique, non-null results.
On Tue, Apr 7, 2015 at 10:58 AM, David Blaikie <dblaikie at gmail.com> wrote:
>
>
> On Mon, Apr 6, 2015 at 11:27 PM, Lang Hames <lhames at gmail.com> wrote:
>
>> Author: lhames
>> Date: Tue Apr 7 01:27:56 2015
>> New Revision: 234299
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=234299&view=rev
>> Log:
>> [RuntimeDyld] Always allocate at least 1 byte for object sections in the
>> JIT to
>> ensure that section addresses are distinct.
>>
>> mapSectionAddress will fail if two sections are allocated the same
>> address,
>> which can happen if any section has zero size (since malloc(0) is
>> implementation
>> defined). Unfortunately I've been unable to repro this with a simple test
>> case.
>>
>
> Not sure about malloc, but new is guaranteed to give unique addresses even
> for zero size allocations...
>
>
>>
>> Fixes <rdar://problem/20314015>.
>>
>>
>> Modified:
>> llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
>>
>> Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=234299&r1=234298&r2=234299&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)
>> +++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Tue Apr 7
>> 01:27:56 2015
>> @@ -361,19 +361,20 @@ void RuntimeDyldImpl::computeTotalAllocS
>> if (Name == ".eh_frame")
>> SectionSize += 4;
>>
>> - if (SectionSize > 0) {
>> - // save the total size of the section
>> - if (IsCode) {
>> - CodeSectionSizes.push_back(SectionSize);
>> - } else if (IsReadOnly) {
>> - ROSectionSizes.push_back(SectionSize);
>> - } else {
>> - RWSectionSizes.push_back(SectionSize);
>> - }
>> - // update the max alignment
>> - if (Alignment > MaxAlignment) {
>> - MaxAlignment = Alignment;
>> - }
>> + if (!SectionSize)
>> + SectionSize = 1;
>> +
>> + if (IsCode) {
>> + CodeSectionSizes.push_back(SectionSize);
>> + } else if (IsReadOnly) {
>> + ROSectionSizes.push_back(SectionSize);
>> + } else {
>> + RWSectionSizes.push_back(SectionSize);
>> + }
>> +
>> + // update the max alignment
>> + if (Alignment > MaxAlignment) {
>> + MaxAlignment = Alignment;
>> }
>> }
>> }
>> @@ -578,6 +579,8 @@ unsigned RuntimeDyldImpl::emitSection(co
>> if (IsRequired) {
>> Check(Section.getContents(data));
>> Allocate = DataSize + PaddingSize + StubBufSize;
>> + if (!Allocate)
>> + Allocate = 1;
>> Addr = IsCode ? MemMgr.allocateCodeSection(Allocate, Alignment,
>> SectionID,
>> Name)
>> : MemMgr.allocateDataSection(Allocate, Alignment,
>> SectionID,
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150407/d9aaf905/attachment.html>
More information about the llvm-commits
mailing list