qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC 41/48] configure: add --enable-plugins


From: Roman Bolshakov
Subject: Re: [Qemu-devel] [RFC 41/48] configure: add --enable-plugins
Date: Wed, 28 Nov 2018 13:43:30 +0300
User-agent: NeoMutt/20180716

On Tue, Nov 27, 2018 at 06:13:57PM -0500, Emilio G. Cota wrote:
> On Tue, Nov 27, 2018 at 15:43:52 +0300, Roman Bolshakov wrote:
> > ld64 on macOS has similar -exported_symbols_list option. Here's the 
> > reference:
> > 
> >      -exported_symbols_list filename
> >     The specified filename contains a list of global symbol names
> >     that will remain as global symbols in the output file.  All other
> >     global symbols will be treated as if they were marked as
> >     __private_extern__ (aka visibility=hidden) and will not be global in
> >     the output file. The symbol names listed in filename must be one per
> >     line.  Leading and trailing white space are not part of the symbol
> >     name.  Lines starting with # are ignored, as are lines with only white
> >     space.  Some wildcards (similar to shell file matching) are supported.
> >     The * matches zero or more characters.  The ?  matches one character.
> >     [abc] matches one character which must be an 'a', 'b', or 'c'.
> >     [a-z] matches any single lower case letter from 'a' to 'z'.
> > 
> > 
> > I can try your branch if you add support of the linker flag or send required
> > changes via GitHub.
> 
> Can you please try this branch? I added a commit with the appended.
>   https://github.com/cota/qemu/tree/plugin-v2
> 
> You can inspect the symbols in the final binary with
> `readelf --dyn-syms' or `nm -D'.
> 
> Thanks,
> 
>               Emilio
> 
> ---
> diff --git a/configure b/configure
> index fe9707d951..3dc9c9697b 100755
> --- a/configure
> +++ b/configure
> @@ -5176,15 +5176,31 @@ int main(void)
>  }
>  EOF
>  
> +ld_dynamic_list="no"
>  if compile_prog "" "-Wl,--dynamic-list=$TMPTXT" ; then
>    ld_dynamic_list="yes"
> -else
> -  if test "$plugins" = "yes" ; then
> -    error_exit \
> -        "Plugin support requires specifying a set of symbols that " \
> -        "are exported to plugins. Unfortunately your linker doesn't " \
> -        "support the flag (--dynamic-list) used for this purpose."
> -  fi
> +fi
> +
> +#########################################
> +# See if -exported_symbols_list is supported by the linker
> +
> +cat > $TMPTXT <<EOF
> +  foo
> +EOF
> +
> +ld_exported_symbols_list="no"
> +if compile_prog "" "-Wl,-exported_symbols_list,$TMPTXT" ; then
> +  ld_exported_symbols_list="yes"
> +fi
> +
> +if  test "$plugins" = "yes" &&
> +    test "$ld_dynamic_list" = "no" &&
> +    test "$ld_exported_symbols_list" = "no" ; then
> +  error_exit \
> +      "Plugin support requires specifying a set of symbols that " \
> +      "are exported to plugins. Unfortunately your linker doesn't " \
> +      "support the flag (--dynamic-list or -exported_symbols_list) used " \
> +      "for this purpose."
>  fi
>  
>  ########################################
> @@ -6827,7 +6843,18 @@ fi
>  if test "$plugins" = "yes" ; then
>      echo "CONFIG_PLUGINS=y" >> $config_host_mak
>      LIBS="-ldl $LIBS"
> -    LDFLAGS="-Wl,--dynamic-list=\$(SRC_PATH)/qemu-plugins.symbols $LDFLAGS"
> +    if test "$ld_dynamic_list" = "yes" ; then
> +     LDFLAGS="-Wl,--dynamic-list=\$(SRC_PATH)/qemu-plugins.symbols $LDFLAGS"
> +    elif test "$ld_exported_symbols_list" = "yes" ; then
> +     ld64_symbols=qemu-plugins-ld64.symbols
> +     echo "# Automatically generated by configure - do not modify" > 
> $ld64_symbols
> +     cat "$source_path/qemu-plugins.symbols" | grep qemu_ | sed 's/;//g' >> 
> $ld64_symbols
> +     LDFLAGS="-Wl,-exported_symbols_list,\$(BUILD_DIR)/$ld64_symbols 
> $LDFLAGS"
> +    else
> +     error_exit \
> +         "If \$plugins=yes, either \$ld_dynamic_list or " \
> +         "\$ld_exported_symbols_list should have been set to 'yes'."
> +    fi
>  fi
>  
>  if test "$tcg_interpreter" = "yes"; then
> 

Hi Emilio,

The test of -exported_symbols_list fails:
Undefined symbols for architecture x86_64:
  "foo", referenced from:
       -exported_symbol[s_list] command line option
            (maybe you meant: _foo)

All functions on macOS are prefixed with underscore [1]:
"The name of a symbol representing a function that conforms to standard C
calling conventions is the name of the function with an underscore prefix.
Thus, the name of the symbol representing the function main would be _main."

So it can be fixed by prepending foo and qemu-plugins-ld64.symbols with
underscore:

diff --git a/configure b/configure
index 3dc9c9697b..85dd15732c 100755
--- a/configure
+++ b/configure
@@ -5185,7 +5185,7 @@ fi
 # See if -exported_symbols_list is supported by the linker

 cat > $TMPTXT <<EOF
-  foo
+  _foo
 EOF

 ld_exported_symbols_list="no"
@@ -6848,7 +6848,7 @@ if test "$plugins" = "yes" ; then
     elif test "$ld_exported_symbols_list" = "yes" ; then
        ld64_symbols=qemu-plugins-ld64.symbols
        echo "# Automatically generated by configure - do not modify" > 
$ld64_symbols
-       cat "$source_path/qemu-plugins.symbols" | grep qemu_ | sed 's/;//g' >> 
$ld64_symbols
+        cat "$source_path/qemu-plugins.symbols" | sed -nE 
's/^([[:space:]]+)(.+);/\1_\2/p' >> $ld64_symbols
        LDFLAGS="-Wl,-exported_symbols_list,\$(BUILD_DIR)/$ld64_symbols 
$LDFLAGS"
     else
        error_exit \

--

Then if I print globally defined functions I can see it in
config-temp/qemu-conf.exe:

nm -g -U config-temp/qemu-conf.exe
0000000100000f50 T _foo

qemu-ga fails to link because it doesn't have symbols declared in
qemu-plugins-ld64.symbols. Perhaps "-Wl,-exported_symbols_list" should
be applied only to qemu-system?

[1] 
https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/MachOTopics/1-Articles/executing_files.html#//apple_ref/doc/uid/TP40001829-97182-TPXREF112

Best regards,
Roman



reply via email to

[Prev in Thread] Current Thread [Next in Thread]