[PATCH] D90897: [llvm-objcopy] --only-keep-debug: place zero-size segment according to its parent segment

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 12 23:53:14 PST 2020


jhenderson added a comment.

In D90897#2392316 <https://reviews.llvm.org/D90897#2392316>, @enh wrote:

> In D90897#2385929 <https://reviews.llvm.org/D90897#2385929>, @MaskRay wrote:
>
>> In D90897#2385176 <https://reviews.llvm.org/D90897#2385176>, @jhenderson wrote:
>>
>>> In D90897#2379198 <https://reviews.llvm.org/D90897#2379198>, @MaskRay wrote:
>>>
>>>> In D90897#2378385 <https://reviews.llvm.org/D90897#2378385>, @jhenderson wrote:
>>>>
>>>>> Won't this fail if the PT_LOAD the PT_TLS should be in has a zero size too?
>>>>
>>>> PT_LOAD with p_memsz is invalid on Linux. Attempting to mmap a zero-sized segment will fail.
>>
>> It is both Linux and FreeBSD (according to rL288808 <https://reviews.llvm.org/rL288808>). LLD has removeEmptyPTLoad.
>>
>>> This is an implementation detail that won't necessarily be true for all systems. Kernels could also quite happily ignore zero-sized segments with a trivial piece of code to check the size before calling mmap.
>
> that might have been sensible ... but POSIX actually _requires_ that an mmap() of length 0 fails with EINVAL (it's a "shall fail", not just a "may fail": https://pubs.opengroup.org/onlinepubs/9699919799/functions/mmap.html).

Right. What I was referring to was that a kernel which uses mmap to map PT_LOAD segments into memory could have a simple `if(p_memsz != 0)` clause to skip the call of mmap in the first place. So this wasn't a reference to what mmap may or may not do, it was a reference to what the kernel might do when faced with a PT_LOAD of size 0.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D90897/new/

https://reviews.llvm.org/D90897



More information about the llvm-commits mailing list