unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] test/T360-symbol-hiding: use readelf in place of nm
@ 2020-12-11 17:17 David Bremner
  2020-12-12 18:46 ` Tomi Ollila
  0 siblings, 1 reply; 3+ messages in thread
From: David Bremner @ 2020-12-11 17:17 UTC (permalink / raw)
  To: notmuch; +Cc: David Bremner

It turns out that using nm -P isn't as portable as hoped. In particular on
architectures using ELF v1 (e.g. ppc64), the desired symbols end up in
the data section instead of text.

The test is currently only functional on ELF based architectures, so I
think it's legit to depend on readelf instead of nm.

The switch to readelf has the advantage that we can explicitely ask
for all of the symbols with global visibility, rather than grepping
for notmuch. That seems a more robust approach since it will catch any
strangely named global symbols.
---
 test/T360-symbol-hiding.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/test/T360-symbol-hiding.sh b/test/T360-symbol-hiding.sh
index b34f1e54..4e5007da 100755
--- a/test/T360-symbol-hiding.sh
+++ b/test/T360-symbol-hiding.sh
@@ -26,7 +26,8 @@ test_begin_subtest 'checking output'
 test_expect_equal "$result" "$output"
 
 test_begin_subtest 'comparing existing to exported symbols'
-nm -P $NOTMUCH_BUILDDIR/lib/libnotmuch.so | awk '$2 == "T" && $1 ~ "^notmuch" {print $1}' | sort | uniq > ACTUAL
+readelf -Ws $NOTMUCH_BUILDDIR/lib/libnotmuch.so | \
+    awk '$4  == "FUNC" && $5 == "GLOBAL" && $7 != "UND" {print $8}' | sort | uniq > ACTUAL
 sed -n 's/^\(notmuch_[a-zA-Z0-9_]*\)[[:blank:]]*(.*/\1/p' $NOTMUCH_SRCDIR/lib/notmuch.h | sort | uniq > EXPORTED
 test_expect_equal_file EXPORTED ACTUAL
 
-- 
2.29.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] test/T360-symbol-hiding: use readelf in place of nm
  2020-12-11 17:17 [PATCH] test/T360-symbol-hiding: use readelf in place of nm David Bremner
@ 2020-12-12 18:46 ` Tomi Ollila
  2020-12-13 12:58   ` David Bremner
  0 siblings, 1 reply; 3+ messages in thread
From: Tomi Ollila @ 2020-12-12 18:46 UTC (permalink / raw)
  To: David Bremner, notmuch; +Cc: David Bremner

On Fri, Dec 11 2020, David Bremner wrote:

> It turns out that using nm -P isn't as portable as hoped. In particular on
> architectures using ELF v1 (e.g. ppc64), the desired symbols end up in
> the data section instead of text.
>
> The test is currently only functional on ELF based architectures, so I
> think it's legit to depend on readelf instead of nm.
>
> The switch to readelf has the advantage that we can explicitely ask
> for all of the symbols with global visibility, rather than grepping
> for notmuch. That seems a more robust approach since it will catch any
> strangely named global symbols.

Looks good. I use this opportunity to mention that `sort | uniq` can be
replaced with `sort -u`  :D

(also) s/$4  == "FUNC"/$4 == "FUNC"/; i.e. remove one extra space

Tomi

> ---
>  test/T360-symbol-hiding.sh | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/test/T360-symbol-hiding.sh b/test/T360-symbol-hiding.sh
> index b34f1e54..4e5007da 100755
> --- a/test/T360-symbol-hiding.sh
> +++ b/test/T360-symbol-hiding.sh
> @@ -26,7 +26,8 @@ test_begin_subtest 'checking output'
>  test_expect_equal "$result" "$output"
>  
>  test_begin_subtest 'comparing existing to exported symbols'
> -nm -P $NOTMUCH_BUILDDIR/lib/libnotmuch.so | awk '$2 == "T" && $1 ~ "^notmuch" {print $1}' | sort | uniq > ACTUAL
> +readelf -Ws $NOTMUCH_BUILDDIR/lib/libnotmuch.so | \
> +    awk '$4  == "FUNC" && $5 == "GLOBAL" && $7 != "UND" {print $8}' | sort | uniq > ACTUAL
>  sed -n 's/^\(notmuch_[a-zA-Z0-9_]*\)[[:blank:]]*(.*/\1/p' $NOTMUCH_SRCDIR/lib/notmuch.h | sort | uniq > EXPORTED
>  test_expect_equal_file EXPORTED ACTUAL
>  
> -- 
> 2.29.2

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] test/T360-symbol-hiding: use readelf in place of nm
  2020-12-12 18:46 ` Tomi Ollila
@ 2020-12-13 12:58   ` David Bremner
  0 siblings, 0 replies; 3+ messages in thread
From: David Bremner @ 2020-12-13 12:58 UTC (permalink / raw)
  To: Tomi Ollila, notmuch

Tomi Ollila <tomi.ollila@iki.fi> writes:

> On Fri, Dec 11 2020, David Bremner wrote:
>
>> It turns out that using nm -P isn't as portable as hoped. In particular on
>> architectures using ELF v1 (e.g. ppc64), the desired symbols end up in
>> the data section instead of text.
>>
>> The test is currently only functional on ELF based architectures, so I
>> think it's legit to depend on readelf instead of nm.
>>
>> The switch to readelf has the advantage that we can explicitely ask
>> for all of the symbols with global visibility, rather than grepping
>> for notmuch. That seems a more robust approach since it will catch any
>> strangely named global symbols.
>
> Looks good. I use this opportunity to mention that `sort | uniq` can be
> replaced with `sort -u`  :D

I actually did that, but then thought, there must be some reason we do
it this way, maybe portability? Having just checked, I see it's in POSIX
1003.1-2017 (and apparently earlier versions). So I guess it's most likely
safe.

Applied with s/sort|uniq/sort -u/ and one space deleted.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-13 12:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-11 17:17 [PATCH] test/T360-symbol-hiding: use readelf in place of nm David Bremner
2020-12-12 18:46 ` Tomi Ollila
2020-12-13 12:58   ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

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 read-only IMAP folder(s) and NNTP newsgroup(s).