qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v5 6/6] meson: Convert undefsym.sh to undefsym.py


From: Yonggang Luo
Subject: Re: [PATCH v5 6/6] meson: Convert undefsym.sh to undefsym.py
Date: Wed, 26 Aug 2020 23:27:03 +0800

Gotcha, I am confusing about submitting a patch, This is my script to submit patch, but didn't got the things work.


https://wiki.qemu.org/Contribute/SubmitAPatch#Base_patches_against_current_git_master 
Are very long, but I still didn't got the way how to submit patches properly....

Windows bat for submit patch:

```
rd /s /q v2
git format-patch --subject-prefix="PATCH v5" HEAD~6 -o v2/
git send-email --to=qemu-devel@nongnu.org ^
"--cc=Paolo Bonzini ^<pbonzini@redhat.com^>,Daniel P. Berrangé ^<berrange@redhat.com^>" v2
:: git send-email --annotate --to=qemu-devel@nongnu.org --cc=QEMU Developers <qemu-devel@nongnu.org> Paolo Bonzini <pbonzini@redhat.com> v2
pause
``` 

On Wed, Aug 26, 2020 at 11:23 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
Careful, the original script:

-comm -12 \
-  <( $NM -P -g $staticlib | awk '$2!="U"{print "-Wl,-u," $1}' | sort -u) \
-  <( $NM -P -g "$@" | awk '$2=="U"{print "-Wl,-u," $1}' | sort -u)

looks for lines that *are* U in the modules. So using filter_lines_set
is correct for static libraries but wrong for modules.

Paolo

On Wed, Aug 26, 2020 at 5:13 PM <luoyonggang@gmail.com> wrote:
>
> From: Yonggang Luo <luoyonggang@gmail.com>
>
> undefsym.sh are not msys2 compatible, convert it to python script
>
> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
> ---
>  meson.build         |  2 +-
>  scripts/undefsym.py | 56 +++++++++++++++++++++++++++++++++++++++++++++
>  scripts/undefsym.sh | 20 ----------------
>  3 files changed, 57 insertions(+), 21 deletions(-)
>  create mode 100644 scripts/undefsym.py
>  delete mode 100755 scripts/undefsym.sh
>
> diff --git a/meson.build b/meson.build
> index 1644bbd83c..d6e3bcea7e 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -845,7 +845,7 @@ foreach d, list : modules
>  endforeach
>
>  nm = find_program('nm')
> -undefsym = find_program('scripts/undefsym.sh')
> +undefsym = find_program('scripts/undefsym.py')
>  block_syms = custom_target('block.syms', output: 'block.syms',
>                               input: [libqemuutil, block_mods],
>                               capture: true,
> diff --git a/scripts/undefsym.py b/scripts/undefsym.py
> new file mode 100644
> index 0000000000..ebc009fb24
> --- /dev/null
> +++ b/scripts/undefsym.py
> @@ -0,0 +1,56 @@
> +#!/usr/bin/env python3
> +# -*- coding: utf-8 -*-
> +
> +# Before a shared module's DSO is produced, a static library is built for it
> +# and passed to this script.  The script generates -Wl,-u options to force
> +# the inclusion of symbol from libqemuutil.a if the shared modules need them,
> +# This is necessary because the modules may use functions not needed by the
> +# executable itself, which would cause the function to not be linked in.
> +# Then the DSO loading would fail because of the missing symbol.
> +
> +
> +"""
> +Compare the static library for compute the symbol duplication
> +"""
> +
> +import sys
> +import subprocess
> +
> +def filter_lines_set(stdout):
> +    linesSet = set()
> +    for line in stdout.splitlines():
> +        tokens = line.split(b' ')
> +        if len(tokens) >= 1:
> +            if len(tokens) > 1 and tokens[1] == b'U':
> +                continue
> +            new_line = b'-Wl,-u,' + tokens[0]
> +            if not new_line in linesSet:
> +                linesSet.add(new_line)
> +    return linesSet
> +
> +def main(args):
> +    global _SCRIPT
> +    print(" ".join(args),  file=sys.stderr)
> +    if len(args) <= 3:
> +        sys.exit(0)
> +
> +    nm = args[1]
> +    staticlib = args[2]
> +    pc = subprocess.run([nm, "-P", "-g", staticlib], stdout=subprocess.PIPE)
> +    if pc.returncode != 0:
> +        sys.exit(-1)
> +    lines_set_left = filter_lines_set(pc.stdout)
> +
> +    shared_modules = args[3:]
> +    pc = subprocess.run([nm, "-P", "-g"] + shared_modules, stdout=subprocess.PIPE)
> +    if pc.returncode != 0:
> +        sys.exit(-1)
> +    lines_set_right = filter_lines_set(pc.stdout)
> +    lines = []
> +    for line in sorted(list(lines_set_right)):
> +        if line in lines_set_left:
> +            lines.append(line)
> +    sys.stdout.write(b'\n'.join(lines).decode())
> +
> +if __name__ == "__main__":
> +    main(sys.argv)
> diff --git a/scripts/undefsym.sh b/scripts/undefsym.sh
> deleted file mode 100755
> index b9ec332e95..0000000000
> --- a/scripts/undefsym.sh
> +++ /dev/null
> @@ -1,20 +0,0 @@
> -#! /usr/bin/env bash
> -
> -# Before a shared module's DSO is produced, a static library is built for it
> -# and passed to this script.  The script generates -Wl,-u options to force
> -# the inclusion of symbol from libqemuutil.a if the shared modules need them,
> -# This is necessary because the modules may use functions not needed by the
> -# executable itself, which would cause the function to not be linked in.
> -# Then the DSO loading would fail because of the missing symbol.
> -
> -if test $# -le 2; then
> -  exit 0
> -fi
> -
> -NM=$1
> -staticlib=$2
> -shift 2
> -# Find symbols defined in static libraries and undefined in shared modules
> -comm -12 \
> -  <( $NM -P -g $staticlib | awk '$2!="U"{print "-Wl,-u," $1}' | sort -u) \
> -  <( $NM -P -g "$@" | awk '$2=="U"{print "-Wl,-u," $1}' | sort -u)
> --
> 2.27.0.windows.1
>



--
         此致

罗勇刚
Yours
    sincerely,
Yonggang Luo

reply via email to

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