labath added a comment.

In D78972#2008129 <https://reviews.llvm.org/D78972#2008129>, @jingham wrote:

> In D78972#2007493 <https://reviews.llvm.org/D78972#2007493>, @labath wrote:
>
> > > I don't have a way to write a C-based test for this as I don't know how 
> > > to craft a user expression in C that will make such a thing. I asked 
> > > around a bit and nobody had an easy way to do this.
> >
> > Grepping clang's tests for `weak_odr` was very educational. The most 
> > portable way to produce this linkage seems to be:
> >
> >   template<typename T> void f() {}
> >   template void f<int>();
> >
> >
> > As for whether this patch is correct -- I don't know. The weak_odr 
> > functions are allowed to be replaced (that's the `weak` part), but the 
> > replacement is supposed to be equivalent (the `odr` part). So, strictly 
> > speaking, it may be ok to just export this function, but if we wanted to be 
> > closer to what happens for realz, we should check first if there isn't a 
> > more definitive version available elsewhere...
>
>
> I can't get the expression parser to successfully run this code and then call 
> the function in a later evaluation.  Apparently we're not all the way up to 
> creating & instantiating templates.  I tried it with and without this patch 
> and it didn't make any difference.


It seems to work for me:

  $ bin/lldb bin/lldb
  (lldb) target create "bin/lldb"
  Current executable set to 'bin/lldb' (x86_64).
  (lldb) b main
  Breakpoint 1: where = lldb`main, address = 0x00000000000099d0
  (lldb) r
  Process 4504 launched: 'bin/lldb' (x86_64)
  Process 4504 stopped
  * thread #1, name = 'lldb', stop reason = breakpoint 1.1
      frame #0: 0x000055555555d9d0 lldb`main
  lldb`main:
  ->  0x55555555d9d0 <+0>: pushq  %r15
      0x55555555d9d2 <+2>: xorl   %ecx, %ecx
      0x55555555d9d4 <+4>: pushq  %r14
      0x55555555d9d6 <+6>: pushq  %r13
  (lldb) expr --top-level -- template<typename T> void f() { (int)printf("hello 
world\n"); } template void
  f<int>();
  (lldb) expr f<int>()
  hello world



> In the context of the REPL & top-level, I'm not sure how we would find the 
> "equivalent version".  But if it is supposed to be equivalent, is that 
> important for functions the REPL & top-level are generating?

I don't know about REPL, but top-level expressions can interact with (call) 
target functions. If a top-level expression defines a weak symbol that is also 
has a strong definition in the target (or maybe in another top level 
expression), the maybe one would expect that we call the strong definition.

As to why, I guess the reason is that the only thing which enforces this 
"supposed" equivalence is the spectre of undefined behavior. The user will 
(unknowingly) do that anyway, things will go wrong and then they'll try to 
debug it...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78972



_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to