elf: Fix tst-relro-symbols.py argument passing

Message ID 20221214212036.1038959-1-adhemerval.zanella@linaro.org
State Superseded
Headers
Series elf: Fix tst-relro-symbols.py argument passing |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Adhemerval Zanella Netto Dec. 14, 2022, 9:20 p.m. UTC
  Current scheme only consideres the first argument for both --required
and --optional, where the idea is to append a new item.

Checked on x86_64-linux-gnu.
---
 elf/tst-relro-symbols.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Florian Weimer Dec. 14, 2022, 9:45 p.m. UTC | #1
* Adhemerval Zanella:

> Current scheme only consideres the first argument for both --required
> and --optional, where the idea is to append a new item.
>
> Checked on x86_64-linux-gnu.
> ---
>  elf/tst-relro-symbols.py | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/elf/tst-relro-symbols.py b/elf/tst-relro-symbols.py
> index 368ea3349f..41e87b37ea 100644
> --- a/elf/tst-relro-symbols.py
> +++ b/elf/tst-relro-symbols.py
> @@ -56,10 +56,10 @@ def get_parser():
>      """Return an argument parser for this script."""
>      parser = argparse.ArgumentParser(description=__doc__)
>      parser.add_argument('object', help='path to object file to check')
> -    parser.add_argument('--required', metavar='NAME', default=(),
> -                        help='required symbol names', nargs='*')
> -    parser.add_argument('--optional', metavar='NAME', default=(),
> -                        help='required symbol names', nargs='*')
> +    parser.add_argument('--required', metavar='NAME', action='append',
> +                        help='required symbol names')
> +    parser.add_argument('--optional', metavar='NAME', action='append',
> +                        help='required symbol names')
>      return parser
>  
>  def main(argv):

Ugh, right, that's a bug.  But your fix does not seem to work, either:

$ python3 elf/tst-relro-symbols.py --required=undefined --required=_rtld_global_ro   /lib64/ld-linux-x86-64.so.2 
Traceback (most recent call last):
  File "…/src/gnu/glibc/git/elf/tst-relro-symbols.py", line 137, in <module>
    main(sys.argv[1:])
  File "…/src/gnu/glibc/git/elf/tst-relro-symbols.py", line 73, in main
    optional_symbols = frozenset([sym.encode('UTF-8')
                                 ^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not iterable

Thanks,
Florian
  
Adhemerval Zanella Netto Dec. 14, 2022, 10:22 p.m. UTC | #2
On 14/12/22 18:45, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> Current scheme only consideres the first argument for both --required
>> and --optional, where the idea is to append a new item.
>>
>> Checked on x86_64-linux-gnu.
>> ---
>>  elf/tst-relro-symbols.py | 8 ++++----
>>  1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/elf/tst-relro-symbols.py b/elf/tst-relro-symbols.py
>> index 368ea3349f..41e87b37ea 100644
>> --- a/elf/tst-relro-symbols.py
>> +++ b/elf/tst-relro-symbols.py
>> @@ -56,10 +56,10 @@ def get_parser():
>>      """Return an argument parser for this script."""
>>      parser = argparse.ArgumentParser(description=__doc__)
>>      parser.add_argument('object', help='path to object file to check')
>> -    parser.add_argument('--required', metavar='NAME', default=(),
>> -                        help='required symbol names', nargs='*')
>> -    parser.add_argument('--optional', metavar='NAME', default=(),
>> -                        help='required symbol names', nargs='*')
>> +    parser.add_argument('--required', metavar='NAME', action='append',
>> +                        help='required symbol names')
>> +    parser.add_argument('--optional', metavar='NAME', action='append',
>> +                        help='required symbol names')
>>      return parser
>>  
>>  def main(argv):
> 
> Ugh, right, that's a bug.  But your fix does not seem to work, either:
> 
> $ python3 elf/tst-relro-symbols.py --required=undefined --required=_rtld_global_ro   /lib64/ld-linux-x86-64.so.2 
> Traceback (most recent call last):
>   File "…/src/gnu/glibc/git/elf/tst-relro-symbols.py", line 137, in <module>
>     main(sys.argv[1:])
>   File "…/src/gnu/glibc/git/elf/tst-relro-symbols.py", line 73, in main
>     optional_symbols = frozenset([sym.encode('UTF-8')
>                                  ^^^^^^^^^^^^^^^^^^^^
> TypeError: 'NoneType' object is not iterable
> 

It does work for tst-relro-libc.out, although it would be good to allow either
empty --required or --optional.
  

Patch

diff --git a/elf/tst-relro-symbols.py b/elf/tst-relro-symbols.py
index 368ea3349f..41e87b37ea 100644
--- a/elf/tst-relro-symbols.py
+++ b/elf/tst-relro-symbols.py
@@ -56,10 +56,10 @@  def get_parser():
     """Return an argument parser for this script."""
     parser = argparse.ArgumentParser(description=__doc__)
     parser.add_argument('object', help='path to object file to check')
-    parser.add_argument('--required', metavar='NAME', default=(),
-                        help='required symbol names', nargs='*')
-    parser.add_argument('--optional', metavar='NAME', default=(),
-                        help='required symbol names', nargs='*')
+    parser.add_argument('--required', metavar='NAME', action='append',
+                        help='required symbol names')
+    parser.add_argument('--optional', metavar='NAME', action='append',
+                        help='required symbol names')
     return parser
 
 def main(argv):