|
|
194aa3 |
Partial backport of:
|
|
|
194aa3 |
|
|
|
194aa3 |
commit cb7be1590e9b18e272e72eb4e910a7ad06a53bd0
|
|
|
194aa3 |
Author: Joseph Myers <joseph@codesourcery.com>
|
|
|
194aa3 |
Date: Mon Dec 10 22:56:59 2018 +0000
|
|
|
194aa3 |
|
|
|
194aa3 |
Use gen-as-const.py to process .pysym files.
|
|
|
194aa3 |
|
|
|
194aa3 |
This patch eliminates the gen-py-const.awk variant of gen-as-const,
|
|
|
194aa3 |
switching to use of gnu-as-const.py (with a new --python option) to
|
|
|
194aa3 |
process .pysym files (i.e., to generate nptl_lock_constants.py), as
|
|
|
194aa3 |
the syntax of those files is identical to that of .sym files.
|
|
|
194aa3 |
|
|
|
194aa3 |
Note that the generated nptl_lock_constants.py is *not* identical to
|
|
|
194aa3 |
the version generated by the awk script. Apart from the trivial
|
|
|
194aa3 |
changes (comment referencing the new script, and output being sorted),
|
|
|
194aa3 |
the constant FUTEX_WAITERS, PTHREAD_MUTEXATTR_FLAG_BITS,
|
|
|
194aa3 |
PTHREAD_MUTEXATTR_FLAG_PSHARED and PTHREAD_MUTEX_PRIO_CEILING_MASK are
|
|
|
194aa3 |
now output as positive rather than negative constants (on x86_64
|
|
|
194aa3 |
anyway; maybe not necessarily on 32-bit systems):
|
|
|
194aa3 |
|
|
|
194aa3 |
< FUTEX_WAITERS = -2147483648
|
|
|
194aa3 |
---
|
|
|
194aa3 |
> FUTEX_WAITERS = 2147483648
|
|
|
194aa3 |
|
|
|
194aa3 |
< PTHREAD_MUTEXATTR_FLAG_BITS = -251662336
|
|
|
194aa3 |
< PTHREAD_MUTEXATTR_FLAG_PSHARED = -2147483648
|
|
|
194aa3 |
---
|
|
|
194aa3 |
> PTHREAD_MUTEXATTR_FLAG_BITS = 4043304960
|
|
|
194aa3 |
> PTHREAD_MUTEXATTR_FLAG_PSHARED = 2147483648
|
|
|
194aa3 |
|
|
|
194aa3 |
< PTHREAD_MUTEX_PRIO_CEILING_MASK = -524288
|
|
|
194aa3 |
---
|
|
|
194aa3 |
> PTHREAD_MUTEX_PRIO_CEILING_MASK = 4294443008
|
|
|
194aa3 |
|
|
|
194aa3 |
This is because gen-as-const has a cast of the constant value to long
|
|
|
194aa3 |
int, which gen-py-const lacks.
|
|
|
194aa3 |
|
|
|
194aa3 |
I think the positive values are more logically correct, since the
|
|
|
194aa3 |
constants in question are in fact unsigned in C. But to reliably
|
|
|
194aa3 |
produce gen-as-const.py output for constants that always (in C and
|
|
|
194aa3 |
Python) reflects the signedness of values with the high bit of "long
|
|
|
194aa3 |
int" set would mean more complicated logic needs to be used in
|
|
|
194aa3 |
computing values.
|
|
|
194aa3 |
|
|
|
194aa3 |
The more correct positive values by themselves produce a failure of
|
|
|
194aa3 |
nptl/test-mutexattr-printers, because masking with
|
|
|
194aa3 |
~PTHREAD_MUTEXATTR_FLAG_BITS & ~PTHREAD_MUTEX_NO_ELISION_NP now leaves
|
|
|
194aa3 |
a bit -1 << 32 in the Python value, resulting in a KeyError exception.
|
|
|
194aa3 |
To avoid that, places masking with ~ of one of the constants in
|
|
|
194aa3 |
question are changed to mask with 0xffffffff as well (this reflects
|
|
|
194aa3 |
how ~ in Python applies to an infinite-precision integer whereas ~ in
|
|
|
194aa3 |
C does not do any promotions beyond the width of int).
|
|
|
194aa3 |
|
|
|
194aa3 |
Tested for x86_64.
|
|
|
194aa3 |
|
|
|
194aa3 |
* scripts/gen-as-const.py (main): Handle --python option.
|
|
|
194aa3 |
* scripts/gen-py-const.awk: Remove.
|
|
|
194aa3 |
* Makerules (py-const-script): Use gen-as-const.py.
|
|
|
194aa3 |
($(py-const)): Likewise.
|
|
|
194aa3 |
* nptl/nptl-printers.py (MutexPrinter.read_status_no_robust): Mask
|
|
|
194aa3 |
with 0xffffffff together with ~(PTHREAD_MUTEX_PRIO_CEILING_MASK).
|
|
|
194aa3 |
(MutexAttributesPrinter.read_values): Mask with 0xffffffff
|
|
|
194aa3 |
together with ~PTHREAD_MUTEXATTR_FLAG_BITS and
|
|
|
194aa3 |
~PTHREAD_MUTEX_NO_ELISION_NP.
|
|
|
194aa3 |
* manual/README.pretty-printers: Update reference to
|
|
|
194aa3 |
gen-py-const.awk.
|
|
|
194aa3 |
|
|
|
194aa3 |
Only the gen-as-const.py changes are included downstream. We keep using
|
|
|
194aa3 |
gen-py-const.awk for the build.
|
|
|
194aa3 |
|
|
|
194aa3 |
diff --git a/scripts/gen-as-const.py b/scripts/gen-as-const.py
|
|
|
194aa3 |
index f85e359394acb1a4..2f1dff092b98e044 100644
|
|
|
194aa3 |
--- a/scripts/gen-as-const.py
|
|
|
194aa3 |
+++ b/scripts/gen-as-const.py
|
|
|
194aa3 |
@@ -75,6 +75,8 @@ def main():
|
|
|
194aa3 |
help='C compiler (including options) to use')
|
|
|
194aa3 |
parser.add_argument('--test', action='store_true',
|
|
|
194aa3 |
help='Generate test case instead of header')
|
|
|
194aa3 |
+ parser.add_argument('--python', action='store_true',
|
|
|
194aa3 |
+ help='Generate Python file instead of header')
|
|
|
194aa3 |
parser.add_argument('sym_file',
|
|
|
194aa3 |
help='.sym file to process')
|
|
|
194aa3 |
args = parser.parse_args()
|
|
|
194aa3 |
@@ -103,6 +105,13 @@ def main():
|
|
|
194aa3 |
sym_data.append('START')
|
|
|
194aa3 |
if args.test:
|
|
|
194aa3 |
print(gen_test(sym_data))
|
|
|
194aa3 |
+ elif args.python:
|
|
|
194aa3 |
+ consts = glibcextract.compute_c_consts(sym_data, args.cc)
|
|
|
194aa3 |
+ print('# GENERATED FILE\n'
|
|
|
194aa3 |
+ '\n'
|
|
|
194aa3 |
+ '# Constant definitions.\n'
|
|
|
194aa3 |
+ '# See gen-as-const.py for details.\n')
|
|
|
194aa3 |
+ print(''.join('%s = %s\n' % c for c in sorted(consts.items())), end='')
|
|
|
194aa3 |
else:
|
|
|
194aa3 |
consts = glibcextract.compute_c_consts(sym_data, args.cc)
|
|
|
194aa3 |
print(''.join('#define %s %s\n' % c for c in sorted(consts.items())), end='')
|