[PATCH] build: Fix elf-dynamic-info-soname.

  • Done
  • quality assurance status badge
Details
3 participants
  • Dion Mendel
  • Ludovic Courtès
  • Maxime Devos
Owner
unassigned
Submitted by
Dion Mendel
Severity
normal
D
D
Dion Mendel wrote on 20 Apr 2021 21:44
(address . guix-patches@gnu.org)
20210420194429.GB29387@dm9.info
* guix/build/gremlin.scm (elf-dynamic-info-soname): Return the value of
the dynamic-entry instead of the dynamic-entry record itself.
---
guix/build/gremlin.scm | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

Toggle diff (18 lines)
diff --git a/guix/build/gremlin.scm b/guix/build/gremlin.scm
index e8ea66dfb3..4a31c3cfaf 100644
--- a/guix/build/gremlin.scm
+++ b/guix/build/gremlin.scm
@@ -215,7 +215,10 @@ string table if the type is a string."
(#f #f)
((? elf-segment? dynamic)
(let ((entries (dynamic-entries elf dynamic)))
- (%elf-dynamic-info (find (matching-entry DT_SONAME) entries)
+ (%elf-dynamic-info (or (and=> (find (matching-entry DT_SONAME)
+ entries)
+ dynamic-entry-value)
+ #f)
(filter-map (lambda (entry)
(and (= (dynamic-entry-type entry)
DT_NEEDED)
--
2.31.0
D
D
Dion Mendel wrote on 21 Apr 2021 04:46
(address . 47921@debbugs.gnu.org)
20210421024650.GA30794@dm9.info
Oops, forgot to refactor. Replacement patch attached.

Rationale:

The elf-dynamic-info-soname function is currently implemented but
unused. The current implementation does not work as it omits unwrapping
the dynamic-entry record. This patch makes the function work as
intended.
From b15d9d708900f6713e5f40afdce66f3bb443e36b Mon Sep 17 00:00:00 2001
From: Dion Mendel <guix@dm9.info>
Date: Wed, 21 Apr 2021 10:36:32 +0800
Subject: [PATCH] build: Fix elf-dynamic-info-soname.

* guix/build/gremlin.scm (elf-dynamic-info-soname): Return the value of
the dynamic-entry instead of the dynamic-entry record.
---
guix/build/gremlin.scm | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

Toggle diff (17 lines)
diff --git a/guix/build/gremlin.scm b/guix/build/gremlin.scm
index e8ea66dfb3..4710502426 100644
--- a/guix/build/gremlin.scm
+++ b/guix/build/gremlin.scm
@@ -215,7 +215,9 @@ string table if the type is a string."
(#f #f)
((? elf-segment? dynamic)
(let ((entries (dynamic-entries elf dynamic)))
- (%elf-dynamic-info (find (matching-entry DT_SONAME) entries)
+ (%elf-dynamic-info (and=> (find (matching-entry DT_SONAME)
+ entries)
+ dynamic-entry-value)
(filter-map (lambda (entry)
(and (= (dynamic-entry-type entry)
DT_NEEDED)
--
2.31.0
M
M
Maxime Devos wrote on 21 Apr 2021 13:49
76bb70d22fed27efd4a15308abdd9e95fb1aa929.camel@telenet.be
Dion Mendel schreef op wo 21-04-2021 om 03:44 [+0800]:
Toggle quote (3 lines)
> * guix/build/gremlin.scm (elf-dynamic-info-soname): Return the value of
> the dynamic-entry instead of the dynamic-entry record itself.

1. IIUC, this change would cause a world-rebuild, so this patch would have
to applied on core-updates. The subject line should have been
[PATCH core-updates]: etcetera.
2. How did you test this patch?
3. What does this patch fix?
4. elf-dynamic-info-soname is a record accessor. Did you mean elf-dynamic-info?
5. According to the docstring (core-updates, c9a61dff8242612ae8275829a5ee31ff45ff08b1):

"Return dynamic-link information for ELF as an <elf-dynamic-info> object, or
#f if ELF lacks dynamic-link information."

So this patch actually _introduces_ a bug. Or you need to modify the docstring
as well.

Greetings,
Maxime.
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYIARTRccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7s4+AQCLYWoM4kFdfx71ROh7Einp1SkI
1pDYaIj02WLFBsxPnwEAsCSVBbYQpEHrWrtKuSlmhUzMzezudedJ8cPPKHRqVwQ=
=xFl0
-----END PGP SIGNATURE-----


D
D
Dion Mendel wrote on 21 Apr 2021 17:46
(address . 47921@debbugs.gnu.org)
20210421154612.GA956@dm9.info
Thanks for the follow up.

Toggle quote (4 lines)
>1. IIUC, this change would cause a world-rebuild, so this patch would
>have to applied on core-updates. The subject line should have been
>[PATCH core-updates]: etcetera.

Are you sure? This patch will modify guix.

guix graph --type=reverse-package guix

Only shows a few packages to be rebuilt. I am new to guix so I may be
wrong about this.

Toggle quote (2 lines)
>2. How did you test this patch?

Tested in the repl.

Current behaviour:

(elf-dynamic-info-soname
(call-with-input-file "/path/to/libz.so.1.2.11"
(compose elf-dynamic-info parse-elf
get-bytevector-all)))
=> #<<dynamic-entry> type: 14 value: "libz.so.1" offset: 5764>

There is no way to extract the value as dynamic-entry is private to the
module.

After the patch:

(elf-dynamic-info-soname
(call-with-input-file "/path/to/libz.so.1.2.11"
(compose elf-dynamic-info parse-elf
get-bytevector-all)))
=> "libz.so.1"

Toggle quote (2 lines)
>3. What does this patch fix?

Module (guix build gremlin) exports several functions to extract
information from the dynamic section of an elf file.

elf-dynamic-info-soname is one of these functions. It is not called
anywhere in guix. I would like to use it for packaging, but it is
currently non functioning.

Toggle quote (3 lines)
>4. elf-dynamic-info-soname is a record accessor. Did you mean
>elf-dynamic-info?

No, I do not mean elf-dynamic-info.

elf-dynamic-info-soname is a record accessor which is currently broken
because it doesn't unwrap an internal structure, namely <dynamic-entry>.
All the other accessors unwrap this internal structure.

This patch brings this accessor into line with the others.

Toggle quote (8 lines)
>5. According to the docstring (core-updates, c9a61dff8242612ae8275829a5ee31ff45ff08b1):
>
> "Return dynamic-link information for ELF as an <elf-dynamic-info> object, or
>#f if ELF lacks dynamic-link information."
>
> So this patch actually _introduces_ a bug. Or you need to modify the docstring
> as well.

No. This patch does not affect elf-dynamic-info. It fixes one of its
accessors. Nothing else is affected.
M
M
Maxime Devos wrote on 21 Apr 2021 20:33
92c4f265369735c71c6f358cfee29fb7cc6a38d2.camel@telenet.be
Dion Mendel schreef op wo 21-04-2021 om 23:46 [+0800]:
Toggle quote (13 lines)
> Thanks for the follow up.
>
> > 1. IIUC, this change would cause a world-rebuild, so this patch would
> > have to applied on core-updates. The subject line should have been
> > [PATCH core-updates]: etcetera.
>
> Are you sure? This patch will modify guix.
>
> guix graph --type=reverse-package guix
>
> Only shows a few packages to be rebuilt. I am new to guix so I may be
> wrong about this.

If this patch modified something in, say, guix/scripts or gnu/packages,
targetting "master" should be perfectly fine. But this patch modifies
something under guix/build. Modules under guix/build can be used from
the build environment, that is, from within the compilation process of
a package. By modifying guix/build/gremlin.scm, a widely-used module
in package definitions (used indirectly via gnu-build-system IIRC),
practically all packages would be rebuilt.

Unless I'm severely mistaken, you can see this for yourself by:

0. start from a checkout of guix *without* your patch
1. # you probably have its dependencies already, but let's make sure
./pre-inst-env guix build hello
2. apply your patch to your local checkout of guix
3. make
4. ./pre-inst-env guix build hello
# This will probably rebuild GCC, binutils, etc.!

Toggle quote (23 lines)
> 2. How did you test this patch?
>
> Tested in the repl.
>
> Current behaviour:
>
> (elf-dynamic-info-soname
> (call-with-input-file "/path/to/libz.so.1.2.11"
> (compose elf-dynamic-info parse-elf
> get-bytevector-all)))
> => #<<dynamic-entry> type: 14 value: "libz.so.1" offset: 5764>
>
> There is no way to extract the value as dynamic-entry is private to the
> module.
>
> After the patch:
>
> (elf-dynamic-info-soname
> (call-with-input-file "/path/to/libz.so.1.2.11"
> (compose elf-dynamic-info parse-elf
> get-bytevector-all)))
> => "libz.so.1"

So you didn't try to build any package with this patch?

I would recommend to make sure this patch doesn't break any packages.
While you can't test all packages (unless you have a *really big* build
farm), I would at least suggest running "./pre-inst-env guix build hello".
If that takes too long to complete, don't worry, just interrupt it and let
us now you couldn't test it completely.

To make sure this new functionality does not break in the future, please
write an unit test (in tests/gremlin.scm).

Toggle quote (9 lines)
> > 3. What does this patch fix?
>
> Module (guix build gremlin) exports several functions to extract
> information from the dynamic section of an elf file.
>
> elf-dynamic-info-soname is one of these functions. It is not called
> anywhere in guix. I would like to use it for packaging, but it is
> currently non functioning.

Your patch doesn't modify elf-dynamic-info-soname. It modifies elf-dynamic-info.

Toggle quote (3 lines)
> > 4. elf-dynamic-info-soname is a record accessor. Did you mean
> > elf-dynamic-info?

In case I wasn't clear, I was referring to the commit message. In the commit
message, you say you modified elf-dynamic-info-soname, but you actually modified
elf-dynamic-info.
Toggle quote (1 lines)
> No, I do not mean elf-dynamic-info.
See two comments above.

Toggle quote (1 lines)
> elf-dynamic-info-soname is a record accessor which is currently broken
Record accessors are correct by construction. Perhaps you meant
that the "soname" field is initialised incorrectly by elf-dynamic-info?

Toggle quote (2 lines)
> because it doesn't unwrap an internal structure, namely <dynamic-entry>.
> All the other accessors unwrap this internal structure.
I think you can predict my response about accessors here (-:.

I'll interpret this as ‘in all other fields, the internal structure is unwrapped’.
That's a good point! Your patch seems good to me, but the commit message doesn't
and it has a lack of testing.

Toggle quote (2 lines)
> This patch brings this accessor into line with the others.

You didn't modify the elf-dynamic-info-soname, you modified elf-dynamic-info.
See comments above.

Toggle quote (8 lines)
> > 5. According to the docstring (core-updates, c9a61dff8242612ae8275829a5ee31ff45ff08b1):
> >
> > "Return dynamic-link information for ELF as an <elf-dynamic-info> object, or
> > #f if ELF lacks dynamic-link information."
> >
> > So this patch actually _introduces_ a bug. Or you need to modify the docstring
> > as well.

On second thought, the (revised) patch actually seems correct, and my comment here
doesn't make much sense.

Toggle quote (3 lines)
> No. This patch does not affect elf-dynamic-info. It fixes one of its
> accessors.

You modified elf-dynamic-info, so this patch does affect it.
elf-dynamic-info is a procedure, so it cannot have any accessors (unless you play
weird tricks with Guile's undocumented ‘applicable structs’). The record is
<elf-dynamic-info>. <elf-dynamic-info> != elf-dynamic-info.

Greetings,
Maxime.
-----BEGIN PGP SIGNATURE-----

iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYIBwFxccbWF4aW1lZGV2
b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7pa3AP0eO1dvfn0dRTqTiWeQYeNbjnHo
uojs3GcmouqOm174KQD7BKZGhwJvRAQS2F8rtpY9T8fgmWxBb+CrPMfJqxt6GQY=
=E43E
-----END PGP SIGNATURE-----


D
D
Dion Mendel wrote on 22 Apr 2021 04:55
retitle
(address . 47921@debbugs.gnu.org)
20210422025524.GA2930@dm9.info
retitle 47921 [PATCH core-updates] build: Fix elf-dynamic-info-soname.
D
D
Dion Mendel wrote on 22 Apr 2021 05:13
Re: [bug#47921] [PATCH] build: Fix elf-dynamic-info-soname.
(address . 47921@debbugs.gnu.org)
20210422031350.GB2930@dm9.info
Thanks for your explanations. It's cleared up my understanding.

I've tried to retitled to target core-updates, but I'm not sure if it
applied.

I've updated the patch to include a unit test.

I am currently testing by rebuilding as you suggest.

./pre-inst-env guix build hello

Yes this is building the world so I will report back when it completes.

Toggle quote (2 lines)
>The record is <elf-dynamic-info>. <elf-dynamic-info> != elf-dynamic-info.

Thank you. Yes I was confused regarding this. I've updated the commit
changelog accordingly.
From bfc69ea726e0f5c1955e629e92af377ffb90c2c5 Mon Sep 17 00:00:00 2001
From: Dion Mendel <guix@dm9.info>
Date: Thu, 22 Apr 2021 10:32:35 +0800
Subject: [PATCH] * guix/build/gremlin.scm (elf-dynamic-info): Correctly set
the value of soname in <elf-dynamic-info>.

---
guix/build/gremlin.scm | 4 +++-
tests/gremlin.scm | 18 ++++++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)

Toggle diff (44 lines)
diff --git a/guix/build/gremlin.scm b/guix/build/gremlin.scm
index e8ea66dfb3..4710502426 100644
--- a/guix/build/gremlin.scm
+++ b/guix/build/gremlin.scm
@@ -215,7 +215,9 @@ string table if the type is a string."
(#f #f)
((? elf-segment? dynamic)
(let ((entries (dynamic-entries elf dynamic)))
- (%elf-dynamic-info (find (matching-entry DT_SONAME) entries)
+ (%elf-dynamic-info (and=> (find (matching-entry DT_SONAME)
+ entries)
+ dynamic-entry-value)
(filter-map (lambda (entry)
(and (= (dynamic-entry-type entry)
DT_NEEDED)
diff --git a/tests/gremlin.scm b/tests/gremlin.scm
index b0bb7a8e49..50ad0d70f5 100644
--- a/tests/gremlin.scm
+++ b/tests/gremlin.scm
@@ -96,4 +96,22 @@
(close-pipe pipe)
str)))))))
+(unless c-compiler
+ (test-skip 1))
+(test-equal "elf-dynamic-info-soname"
+ "libfoo.so.2"
+ (call-with-temporary-directory
+ (lambda (directory)
+ (with-directory-excursion directory
+ (call-with-output-file "t.c"
+ (lambda (port)
+ (display "// empty file" port)))
+ (invoke c-compiler "t.c"
+ "-shared" "-Wl,-soname,libfoo.so.2")
+ (let* ((dyninfo (elf-dynamic-info
+ (parse-elf (call-with-input-file "a.out"
+ get-bytevector-all))))
+ (soname (elf-dynamic-info-soname dyninfo)))
+ soname)))))
+
(test-end "gremlin")
--
2.31.0
D
D
Dion Mendel wrote on 22 Apr 2021 05:26
Include correct commit message
(address . 47921@debbugs.gnu.org)
20210422032605.GA3138@dm9.info
Correct changelog message.
From c9df762924ac28bc7cab6c7c1f9acda0db378f7e Mon Sep 17 00:00:00 2001
From: Dion Mendel <guix@dm9.info>
Date: Thu, 22 Apr 2021 11:21:35 +0800
Subject: [PATCH] build: Fix elf-dynamic-info-soname.

* guix/build/gremlin.scm (elf-dynamic-info): Correctly set the value of soname in <elf-dynamic-info>.
---
guix/build/gremlin.scm | 4 +++-
tests/gremlin.scm | 18 ++++++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)

Toggle diff (44 lines)
diff --git a/guix/build/gremlin.scm b/guix/build/gremlin.scm
index e8ea66dfb3..4710502426 100644
--- a/guix/build/gremlin.scm
+++ b/guix/build/gremlin.scm
@@ -215,7 +215,9 @@ string table if the type is a string."
(#f #f)
((? elf-segment? dynamic)
(let ((entries (dynamic-entries elf dynamic)))
- (%elf-dynamic-info (find (matching-entry DT_SONAME) entries)
+ (%elf-dynamic-info (and=> (find (matching-entry DT_SONAME)
+ entries)
+ dynamic-entry-value)
(filter-map (lambda (entry)
(and (= (dynamic-entry-type entry)
DT_NEEDED)
diff --git a/tests/gremlin.scm b/tests/gremlin.scm
index b0bb7a8e49..50ad0d70f5 100644
--- a/tests/gremlin.scm
+++ b/tests/gremlin.scm
@@ -96,4 +96,22 @@
(close-pipe pipe)
str)))))))
+(unless c-compiler
+ (test-skip 1))
+(test-equal "elf-dynamic-info-soname"
+ "libfoo.so.2"
+ (call-with-temporary-directory
+ (lambda (directory)
+ (with-directory-excursion directory
+ (call-with-output-file "t.c"
+ (lambda (port)
+ (display "// empty file" port)))
+ (invoke c-compiler "t.c"
+ "-shared" "-Wl,-soname,libfoo.so.2")
+ (let* ((dyninfo (elf-dynamic-info
+ (parse-elf (call-with-input-file "a.out"
+ get-bytevector-all))))
+ (soname (elf-dynamic-info-soname dyninfo)))
+ soname)))))
+
(test-end "gremlin")
--
2.31.0
L
L
Ludovic Courtès wrote on 22 Apr 2021 10:20
Re: bug#47921: [PATCH] build: Fix elf-dynamic-info-soname.
(name . Dion Mendel)(address . guix@dm9.info)(address . 47921-done@debbugs.gnu.org)
87wnsu20jj.fsf_-_@gnu.org
Hi Dion,

Dion Mendel <guix@dm9.info> skribis:

Toggle quote (11 lines)
>>From bfc69ea726e0f5c1955e629e92af377ffb90c2c5 Mon Sep 17 00:00:00 2001
> From: Dion Mendel <guix@dm9.info>
> Date: Thu, 22 Apr 2021 10:32:35 +0800
> Subject: [PATCH] * guix/build/gremlin.scm (elf-dynamic-info): Correctly set
> the value of soname in <elf-dynamic-info>.
>
> ---
> guix/build/gremlin.scm | 4 +++-
> tests/gremlin.scm | 18 ++++++++++++++++++
> 2 files changed, 21 insertions(+), 1 deletion(-)

Awesome. I tweaked the commit message and applied it.

Thank you, and thanks Maxime for the review!

Ludo’.
Closed
?