<div dir="ltr">Hi Ed<div><br></div><div>Sorry for late reply and thanks for looking into it.</div><div><br></div><div>Your example fails same way as mine for all combinations static/dynamic gcc/clang.</div><div>Wonder if FreeBSD adds .text section to core files.</div>
<div><br></div><div>What would be result of disassembly for you?</div><div><br></div><div>For me it always looks like that:</div><div><br></div><div><div>dis -b -f</div><div>libc.so.6`__GI_raise:</div><div>   0x7f72a9b11330:  00 00  addb   %al, (%rax)</div>
<div>   0x7f72a9b11332:  00 00  addb   %al, (%rax)</div><div>   0x7f72a9b11334:  00 00  addb   %al, (%rax)</div><div>   0x7f72a9b11336:  00 00  addb   %al, (%rax)</div><div>   0x7f72a9b11338:  00 00  addb   %al, (%rax)</div>
<div>   0x7f72a9b1133a:  00 00  addb   %al, (%rax)</div><div>   0x7f72a9b1133c:  00 00  addb   %al, (%rax)</div><div>   0x7f72a9b1133e:  00 00  addb   %al, (%rax)</div><div>   0x7f72a9b11340:  00 00  addb   %al, (%rax)</div>
<div>   0x7f72a9b11342:  00 00  addb   %al, (%rax)</div><div>   0x7f72a9b11344:  00 00  addb   %al, (%rax)</div><div>   0x7f72a9b11346:  00 00  addb   %al, (%rax)</div><div>   0x7f72a9b11348:  00 00  addb   %al, (%rax)</div>
</div><div>...</div><div><br></div><div>Could you please compare output of readelf/eu-readelf with mine?</div><div><br></div><div>For me it is:</div><div><div>eu-readelf -l core_lnx.1125 </div><div><br></div><div>Program Headers:<br>
</div><div><div>  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align</div><div>  NOTE           0x000388 0x0000000000000000 0x0000000000000000 0x001940 0x000000     0x0</div><div>  LOAD           0x002000 0x0000000000400000 0x0000000000000000 0x000000 0x0c2000 R E 0x1000</div>
<div>  LOAD           0x002000 0x00000000004c2000 0x0000000000000000 0x003000 0x003000 RW  0x1000</div><div>  LOAD           0x005000 0x00000000004c5000 0x0000000000000000 0x006000 0x006000 RW  0x1000</div><div>  LOAD           0x00b000 0x0000000001906000 0x0000000000000000 0x002000 0x002000 RW  0x1000</div>
<div>  LOAD           0x00d000 0x0000000001908000 0x0000000000000000 0x000000 0x021000 RW  0x1000</div><div>  LOAD           0x00d000 0x00007f6e4be02000 0x0000000000000000 0x001000 0x001000     0x1000</div><div>  LOAD           0x00e000 0x00007f6e4be03000 0x0000000000000000 0x800000 0x800000 RW  0x1000</div>
<div>  LOAD           0x80e000 0x00007f6e4c603000 0x0000000000000000 0x001000 0x001000     0x1000</div><div>  LOAD           0x80f000 0x00007f6e4c604000 0x0000000000000000 0x800000 0x800000 RW  0x1000</div><div>  LOAD           0x100f000 0x00007f6e4ce04000 0x0000000000000000 0x001000 0x001000     0x1000</div>
<div>  LOAD           0x1010000 0x00007f6e4ce05000 0x0000000000000000 0x800000 0x800000 RW  0x1000</div><div>  LOAD           0x1810000 0x00007fffcef2b000 0x0000000000000000 0x022000 0x022000 RW  0x1000</div><div>  LOAD           0x1832000 0x00007fffceffe000 0x0000000000000000 0x002000 0x002000 R E 0x1000</div>
<div>  LOAD           0x1834000 0xffffffffff600000 0x0000000000000000 0x001000 0x001000 R E 0x1000</div></div></div><div><br></div><div>I am mostly interested if your core contain for .text sections is non-zero length for phdrs in loaded segments:</div>
<div><br></div><div>For me program .text is not clearly there:</div><div>LOAD           0x002000 0x0000000000400000 0x0000000000000000 0x000000 0x0c2000 R E 0x1000<br></div><div>                                                                                                              ~~~~~~</div>
<div>That would explain the difference for what I and you see.</div><div><br></div><div>IIRC Target::ReadMemory seems to be using m_images at first, but after DynamicLoader kicks in it uses:</div><div><br></div><div>
<pre style="margin-top:0px;margin-bottom:0px">bytes_read<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(170,170,170)">=</span><span style="color:rgb(192,192,192)"> </span>m_process_sp<span style="color:rgb(170,170,170)">-></span>ReadMemory<span style="color:rgb(170,170,170)">(</span>load_addr<span style="color:rgb(170,170,170)">,</span><span style="color:rgb(192,192,192)"> </span>dst<span style="color:rgb(170,170,170)">,</span><span style="color:rgb(192,192,192)"> </span>dst_len<span style="color:rgb(170,170,170)">,</span><span style="color:rgb(192,192,192)"> </span>error<span style="color:rgb(170,170,170)">);</span></pre>

<pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">which obviously returns only zeros for me since core did not contain any data for .text sections.</pre><pre style="margin-top:0px;margin-bottom:0px">
<br></pre><pre style="margin-top:0px;margin-bottom:0px"><div style="font-family:arial;white-space:normal">I wonder if:</div><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">            </span></pre>
<pre style="margin-top:0px;margin-bottom:0px">section_load_list<span style="color:rgb(170,170,170)">.</span>ResolveLoadAddress<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(170,170,170)">(</span>load_addr<span style="color:rgb(170,170,170)">,</span><span style="color:rgb(192,192,192)"> </span>resolved_addr<span style="color:rgb(170,170,170)">);</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre>is doing right thing for me, but I clearly do not understand yet how it works and how should it work.
<pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="font-family:arial;white-space:normal">I'll be looking into it more later today and tomorrow.</span><br>
</pre></pre></div><div><br></div><div>Cheers,</div><div>/Piotr</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-02-20 15:30 GMT+01:00 Ed Maste <span dir="ltr"><<a href="mailto:emaste@freebsd.org" target="_blank">emaste@freebsd.org</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On 19 February 2014 19:09, Piotr Rak <<a href="mailto:piotr.rak@gmail.com">piotr.rak@gmail.com</a>> wrote:<br>

> If you want to give it a shot, I'll attach one of my puppets (10 threads, doing nothing but sleep).<br>
> Also I use bfd linker so it has nothing to do with gold in my case.<br>
<br>
</div>Hi Piotr,<br>
<br>
I'm not able to compile your test code (clang 3.4), but as a data<br>
point I have no trouble with a similar C test case of mine, on<br>
FreeBSD.  Perhaps you can build it and compare.<br>
<br>
My test code is here: <a href="https://github.com/emaste/userland-cores" target="_blank">https://github.com/emaste/userland-cores</a><br>
<br>
(lldb) bt all<br>
* thread #1: tid = 0, 0x0000000800aa03fc libc.so.7`__sys_thr_kill + 12<br>
at thr_kill.S:3, name = 'gen-core-v1', stop reason = signal SIGABRT<br>
  * frame #0: 0x0000000800aa03fc libc.so.7`__sys_thr_kill + 12 at thr_kill.S:3<br>
    frame #1: 0x0000000800b4487b libc.so.7`abort + 75 at abort.c:65<br>
    frame #2: 0x00000000004007c1<br>
gen-core-v1`thread_fn_2(arg=0x0000000000600c20) + 81 at gen-core.c:37<br>
    frame #3: 0x0000000800822dc4<br>
libthr.so.3`thread_start(curthread=0x0000000801008000) + 260 at<br>
thr_create.c:284<br>
<br>
  thread #2: tid = 1, 0x0000000800b2707c libc.so.7`__sys_nanosleep +<br>
12 at nanosleep.S:3, name = 'gen-core-v1', stop reason = signal<br>
SIGABRT<br>
    frame #0: 0x0000000800b2707c libc.so.7`__sys_nanosleep + 12 at nanosleep.S:3<br>
    frame #1: 0x0000000800a929c8 libc.so.7`__sleep(seconds=60) + 40 at<br>
sleep.c:58<br>
    frame #2: 0x0000000800825078 libthr.so.3`___sleep(seconds=60) + 40<br>
at thr_syscalls.c:592<br>
    frame #3: 0x0000000000400755<br>
gen-core-v1`thread_fn_1(arg=0x0000000000600c08) + 69 at gen-core.c:23<br>
    frame #4: 0x0000000800822dc4<br>
libthr.so.3`thread_start(curthread=0x0000000801007c00) + 260 at<br>
thr_create.c:284<br>
<br>
  thread #3: tid = 2, 0x0000000800b2707c libc.so.7`__sys_nanosleep +<br>
12 at nanosleep.S:3, name = 'gen-core-v1', stop reason = signal<br>
SIGABRT<br>
    frame #0: 0x0000000800b2707c libc.so.7`__sys_nanosleep + 12 at nanosleep.S:3<br>
    frame #1: 0x0000000800a929c8 libc.so.7`__sleep(seconds=60) + 40 at<br>
sleep.c:58<br>
    frame #2: 0x0000000800825078 libthr.so.3`___sleep(seconds=60) + 40<br>
at thr_syscalls.c:592<br>
    frame #3: 0x0000000000400755<br>
gen-core-v1`thread_fn_1(arg=0x0000000000600bf0) + 69 at gen-core.c:23<br>
    frame #4: 0x0000000800822dc4<br>
libthr.so.3`thread_start(curthread=0x0000000801007800) + 260 at<br>
thr_create.c:284<br>
<br>
  thread #4: tid = 3, 0x0000000800b2707c libc.so.7`__sys_nanosleep +<br>
12 at nanosleep.S:3, name = 'gen-core-v1', stop reason = signal<br>
SIGABRT<br>
    frame #0: 0x0000000800b2707c libc.so.7`__sys_nanosleep + 12 at nanosleep.S:3<br>
    frame #1: 0x0000000800a929c8 libc.so.7`__sleep(seconds=60) + 40 at<br>
sleep.c:58<br>
    frame #2: 0x0000000800825078 libthr.so.3`___sleep(seconds=60) + 40<br>
at thr_syscalls.c:592<br>
    frame #3: 0x000000000040088f gen-core-v1`main(argc=1,<br>
argv=0x00007fffffffd540) + 191 at gen-core.c:54<br>
    frame #4: 0x0000000000400681 gen-core-v1`_start(ap=<unavailable>,<br>
cleanup=<unavailable>) + 161 at crt1.c:97<br>
</blockquote></div><br></div>