This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Linker plugins should be aware of --defsym during symbol resolution
On Tue, Feb 13, 2018 at 10:24 AM, Cary Coutant <ccoutant@gmail.com> wrote:
> >> Can you explain why this new resolution is needed? Why would
> >> LDPR_PREEMPTED_REG not work?
> >
> > They mean different things. For example, LDPR_PREEMPTED_REG will mean
> that
> > there is a prevailing definition in a regular object file. But if the IR
> def
> > has weak ODR linkage, the LTO implementation knows that all copies must
> be
> > the same, and we can and currently do keep that def around long enough
> for
> > inlining. That would be incorrect in the defsym case, where this symbol
> is
> > actually redefined by the linker. That is what we are trying to
> distinguish.
>
> Do you have a real-world example? I'm having trouble imagining a case
> where --defsym would be used to override a symbol that's subject to
> the ODR and yet remain a valid program.
>
I just concocted one:
$ cat bar.h
#include <stdio.h>
extern inline void bar()
{
fprintf(stderr, "in bar\n");
}
extern inline void baz()
{
fprintf(stderr, "in baz\n");
}
$ cat hello1.cc
#include <stdio.h>
#include "bar.h"
extern void foo();
int main() {
baz();
bar();
foo();
return 0;
}
$ cat hello2.cc
#include <stdio.h>
#include "bar.h"
void foo()
{
bar();
}
Without defsym:
$ ~/llvm/llvm_8_build/bin/clang++ hello[12].cc -fuse-ld=gold
$ a.out
in baz
in bar
in bar
With defsym:
$ ~/llvm/llvm_8_build/bin/clang++ hello[12].cc -fuse-ld=gold
-Wl,--defsym,_Z3barv=_Z3bazv
$ a.out
in baz
in baz
in baz
In this case, because bar is inline it gets weak ODR linkage in the two
translation units.
Teresa
> -cary
>
--
Teresa Johnson | Software Engineer | tejohnson@google.com | 408-460-2413
<(408)%20460-2413>