<div dir="ltr">Makes sense. The address of the Data is 8 byte aligned, but the size of the object is still 36 bytes.<div><br></div><div>David</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 23, 2016 at 12:25 PM, Vedant Kumar <span dir="ltr"><<a href="mailto:vsk@apple.com" target="_blank">vsk@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I see one more spot where this could be an issue in InstrProfiling.c:<br>
<br>
__llvm_profile_reset_counters()<br>
  ...<br>
-  for (DI = DataBegin; DI != DataEnd; ++DI) {<br>
+  for (DI = DataBegin; DI < DataEnd; ++DI) {<br>
<br>
I can fix this up too.<br>
<br>
vedant<br>
<div><div class="h5"><br>
> On Feb 23, 2016, at 12:22 PM, Vedant Kumar via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Yes, it is linker-related but not a linker bug.<br>
><br>
> __llvm_profile_data is only required to _start_ at an 8-byte aligned address.<br>
><br>
> We shouldn't ever need to access past byte 36 of this structure (on i386).<br>
><br>
> In the case of instrprof_basic.c, we have 3 __llvm_profile_data objects. So the linker allocates 40 + 40 + 36 = 116 bytes.<br>
><br>
> The iterator in __llvm_profile_gather_value_data walks past the end of the section. Here is a fix:<br>
><br>
> -  for (I = (__llvm_profile_data *)DataBegin; I != DataEnd; ++I) {<br>
> +  for (I = (__llvm_profile_data *)DataBegin; I < DataEnd; ++I) {<br>
><br>
> Is this good to commit?<br>
><br>
> vedant<br>
><br>
><br>
>> On Feb 23, 2016, at 11:24 AM, Xinliang David Li <<a href="mailto:davidxl@google.com">davidxl@google.com</a>> wrote:<br>
>><br>
>> Is the root cause of the issue understood now?<br>
>><br>
>> thanks,<br>
>><br>
>> David<br>
>><br>
>> On Mon, Feb 22, 2016 at 11:55 AM, Xinliang David Li <<a href="mailto:davidxl@google.com">davidxl@google.com</a>> wrote:<br>
>>> On Mon, Feb 22, 2016 at 11:37 AM, Vedant Kumar <<a href="mailto:vsk@apple.com">vsk@apple.com</a>> wrote:<br>
>>>> vsk added a comment.<br>
>>>><br>
>>>> Hi David,<br>
>>>><br>
>>>> This commit enables tests on 64-bit Darwin which have apparently been failing. I now see:<br>
>>>><br>
>>>> ******************** TEST 'Profile-i386 :: instrprof-basic.c' FAILED ********************<br>
>>>> Script:<br>
>>>> --<br>
>>>> /Users/vk/Desktop/llvm/Debug+Asserts/./bin/clang -arch i386  -fprofile-instr-generate -o /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-basic.c.tmp -O3 /Users/vk/Desktop/llvm/projects/compiler-rt/test/profile/instrprof-basic.c<br>
>>>> env LLVM_PROFILE_FILE=/Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-basic.c.tmp.profraw  /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-basic.c.tmp<br>
>>>> llvm-profdata merge -o /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-basic.c.tmp.profdata /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-basic.c.tmp.profraw<br>
>>>> /Users/vk/Desktop/llvm/Debug+Asserts/./bin/clang -arch i386  -fprofile-instr-use=/Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-basic.c.tmp.profdata -o - -S -emit-llvm /Users/vk/Desktop/llvm/projects/compiler-rt/test/profile/instrprof-basic.c | FileCheck /Users/vk/Desktop/llvm/projects/compiler-rt/test/profile/instrprof-basic.c<br>
>>>> --<br>
>>>> Exit Code: 139<br>
>>>><br>
>>>> Command Output (stderr):<br>
>>>> --<br>
>>>> /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-basic.c.script: line 4: 20417 Segmentation fault: 11  env LLVM_PROFILE_FILE=/Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-basic.c.tmp.profraw /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-basic.c.tmp<br>
>>>><br>
>>>> The segmentation fault is in `__llvm_profile_gather_value_data()`. Accessing `I->Values` dereferences `0x1`:<br>
>>>><br>
>>>> (lldb) p *I<br>
>>>> (__llvm_profile_data) $11 = {<br>
>>>>   NameRef = 10864<br>
>>>>   FuncHash = 48378511633216<br>
>>>>   CounterPtr = 0x00000000<br>
>>>>   FunctionPointer = 0x0000df1e<br>
>>>>   Values = 0x00000001<br>
>>>>   NumCounters = 0<br>
>>>>   NumValueSites = ([0] = 13723)<br>
>>>> }<br>
>>>><br>
>>><br>
>>> Looks like the prof data iterator is returning some garbage entry. For<br>
>>> that test, it should have only 3 entries.  If it iterates more<br>
>>> entries, it is likely a linker bug on darwin.<br>
>>><br>
>>><br>
>>>> There's a second issue with corrupt raw profiles:<br>
>>>><br>
>>>> ********************<br>
>>>> FAIL: Profile-i386 :: instrprof-without-libc.c (39 of 96)<br>
>>>> ******************** TEST 'Profile-i386 :: instrprof-without-libc.c' FAILED ********************<br>
>>>> Script:<br>
>>>> --<br>
>>>> /Users/vk/Desktop/llvm/Debug+Asserts/./bin/clang -arch i386  -fprofile-instr-generate -DCHECK_SYMBOLS -O3 -o /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-without-libc.c.tmp.symbols /Users/vk/Desktop/llvm/projects/compiler-rt/test/profile/instrprof-without-libc.c<br>
>>>> llvm-nm /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-without-libc.c.tmp.symbols | FileCheck /Users/vk/Desktop/llvm/projects/compiler-rt/test/profile/instrprof-without-libc.c --check-prefix=CHECK-SYMBOLS<br>
>>>> /Users/vk/Desktop/llvm/Debug+Asserts/./bin/clang -arch i386  -fprofile-instr-generate -O3 -o /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-without-libc.c.tmp /Users/vk/Desktop/llvm/projects/compiler-rt/test/profile/instrprof-without-libc.c<br>
>>>> /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-without-libc.c.tmp /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-without-libc.c.tmp.profraw<br>
>>>> llvm-profdata merge -o /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-without-libc.c.tmp.profdata /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-without-libc.c.tmp.profraw<br>
>>>> /Users/vk/Desktop/llvm/Debug+Asserts/./bin/clang -arch i386  -fprofile-instr-use=/Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-without-libc.c.tmp.profdata -o - -S -emit-llvm /Users/vk/Desktop/llvm/projects/compiler-rt/test/profile/instrprof-without-libc.c | FileCheck /Users/vk/Desktop/llvm/projects/compiler-rt/test/profile/instrprof-without-libc.c<br>
>>>> --<br>
>>>> Exit Code: 1<br>
>>>><br>
>>>> Command Output (stderr):<br>
>>>> --<br>
>>>> error: /Users/vk/Desktop/llvm/build/projects/compiler-rt/test/profile/Profile-i386/Output/instrprof-without-libc.c.tmp.profraw: Invalid instrumentation profile data (file header is corrupt)<br>
>>>><br>
>>>> This happens because `ProfileSize = 34359738544` (pretty close to 32 GB, which seems wrong):<br>
>>>><br>
>>>>     frame #0: 0x00000001001fa851 llvm-profdata`llvm::RawInstrProfReader<unsigned int>::readHeader(this=0x0000000100b00000, Header=0x0000000100a00110) + 801 at InstrProfReader.cpp:337<br>
>>>>    334<br>
>>>>    335          auto *Start = reinterpret_cast<const char *>(&Header);<br>
>>>>    336          if (Start + ProfileSize > DataBuffer->getBufferEnd())<br>
>>>> -> 337            return error(instrprof_error::bad_header);<br>
>>>><br>
>>><br>
>>> It is likely that ValueDataSize in the header has bogus value. It is<br>
>>> likely related to the bug above -- some bogus function prof data entry<br>
>>> gets processed.<br>
>>><br>
>>><br>
>>>> I don't know if this last issue is affected by this commit, but I'm not sure why these tests are unsupported (they don't seem Linux-specific):<br>
>>><br>
>>> Looks like i386/darwin was never tested before? This just exposed some<br>
>>> latent bug.<br>
>>><br>
>>> thanks,<br>
>>><br>
>>> David<br>
>>><br>
>>>><br>
>>>> UNSUPPORTED: Profile-x86_64 :: Linux/coverage_ctors.cpp (1 of 32)<br>
>>>> UNSUPPORTED: Profile-x86_64 :: Linux/coverage_dtor.cpp (2 of 32)<br>
>>>> UNSUPPORTED: Profile-x86_64 :: Linux/instrprof-basic.c (3 of 32)<br>
>>>> UNSUPPORTED: Profile-x86_64 :: Linux/coverage_test.cpp (4 of 32)<br>
>>>> UNSUPPORTED: Profile-x86_64 :: Linux/coverage_shared.test (5 of 32)<br>
>>>> UNSUPPORTED: Profile-x86_64 :: Linux/instrprof-comdat.test (6 of 32)<br>
>>>> UNSUPPORTED: Profile-x86_64 :: Linux/instrprof-dlopen.test (7 of 32)<br>
>>>> UNSUPPORTED: Profile-x86_64 :: Linux/instrprof-dynamic-one-shared.test (8 of 32)<br>
>>>> UNSUPPORTED: Profile-x86_64 :: Linux/instrprof-dynamic-two-shared.test (9 of 32)<br>
>>>><br>
>>>> For reference, I configure llvm with: `-DCMAKE_CROSSCOMPILING=False -DLLVM_TARGET_ARCH="X86" -DLLVM_TARGETS_TO_BUILD="X86;AArch64;ARM" -DCMAKE_BUILD_TYPE:STRING=Debug -DLLVM_ENABLE_ASSERTIONS=True -DLLVM_INCLUDE_TESTS=True -DLLVM_ENABLE_WARNINGS=False -G 'Ninja' ../`.<br>
>>>><br>
>>>> AFAICT (checking -###), the compiler is grabbing the correct copy of compiler-rt and it has the right slice:<br>
>>>><br>
>>>> $ ninja check-profile [...]<br>
>>>> $ file "/Users/vk/Desktop/llvm/build/bin/../lib/clang/3.9.0/lib/darwin/libclang_rt.profile_osx.a"<br>
>>>> /Users/vk/Desktop/llvm/build/bin/../lib/clang/3.9.0/lib/darwin/libclang_rt.profile_osx.a: Mach-O universal binary with 3 architectures: [i386: current ar archive random library] [x86_64: current ar archive random library] [x86_64h: current ar archive random library]<br>
>>>> /Users/vk/Desktop/llvm/build/bin/../lib/clang/3.9.0/lib/darwin/libclang_rt.profile_osx.a (for architecture i386):     current ar archive random library<br>
>>>> /Users/vk/Desktop/llvm/build/bin/../lib/clang/3.9.0/lib/darwin/libclang_rt.profile_osx.a (for architecture x86_64):   current ar archive random library<br>
>>>> /Users/vk/Desktop/llvm/build/bin/../lib/clang/3.9.0/lib/darwin/libclang_rt.profile_osx.a (for architecture x86_64h):  current ar archive random library<br>
>>>><br>
>>>> I'll try to get to the bottom of this, but any help is appreciated.<br>
>>>><br>
>>>><br>
>>>> Repository:<br>
>>>> rL LLVM<br>
>>>><br>
>>>> <a href="http://reviews.llvm.org/D17361" rel="noreferrer" target="_blank">http://reviews.llvm.org/D17361</a><br>
>>>><br>
>>>><br>
>>>><br>
><br>
</div></div>> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br>
</blockquote></div><br></div>