qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: luoyonggang@gmail.com
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Yonggang Luo" <luoyonggang@gmail.com>,
	"Daniel P . Berrangé" <berrange@redhat.com>
Subject: [PATCH v5 6/6] meson: Convert undefsym.sh to undefsym.py
Date: Wed, 26 Aug 2020 23:10:06 +0800	[thread overview]
Message-ID: <20200826151006.80-6-luoyonggang@gmail.com> (raw)
In-Reply-To: <20200826151006.80-1-luoyonggang@gmail.com>

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



  parent reply	other threads:[~2020-08-26 15:17 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-26 15:10 [PATCH v5 1/6] meson: Fixes the ninjatool issue that E$$: are generated in Makefile.ninja luoyonggang
2020-08-26 15:10 ` [PATCH v5 2/6] meson: fixes relpath may fail on win32 luoyonggang
2020-08-26 15:10 ` [PATCH v5 3/6] meson: Mingw64 gcc doesn't recognize system include_type for sdl2 luoyonggang
2020-08-26 15:10 ` [PATCH v5 4/6] configure: Fix include and linkage issue on msys2 luoyonggang
2020-08-26 15:24   ` Paolo Bonzini
2020-08-26 15:33     ` 罗勇刚(Yonggang Luo)
2020-08-26 15:36       ` Paolo Bonzini
2020-08-26 15:38         ` 罗勇刚(Yonggang Luo)
2020-08-27 16:14   ` Mark Cave-Ayland
2020-08-26 15:10 ` [PATCH v5 5/6] meson: Fixes ninjatool can not be recognized as script under Window/MSYS2 luoyonggang
2020-08-26 15:10 ` luoyonggang [this message]
2020-08-26 15:22   ` [PATCH v5 6/6] meson: Convert undefsym.sh to undefsym.py Paolo Bonzini
2020-08-26 15:27     ` 罗勇刚(Yonggang Luo)
2020-08-26 15:28 ` [PATCH v5 1/6] meson: Fixes the ninjatool issue that E$$: are generated in Makefile.ninja Paolo Bonzini
2020-08-26 15:31   ` 罗勇刚(Yonggang Luo)
2020-08-26 15:36     ` Paolo Bonzini
2020-08-26 15:39       ` 罗勇刚(Yonggang Luo)
2020-08-26 15:41         ` Paolo Bonzini
2020-08-26 15:45           ` 罗勇刚(Yonggang Luo)
2020-08-26 15:47           ` 罗勇刚(Yonggang Luo)
2020-08-26 15:56             ` Paolo Bonzini
2020-08-26 16:09               ` 罗勇刚(Yonggang Luo)
2020-08-26 16:17                 ` 罗勇刚(Yonggang Luo)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200826151006.80-6-luoyonggang@gmail.com \
    --to=luoyonggang@gmail.com \
    --cc=berrange@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).