unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
From: Maxime Devos <maximedevos@telenet.be>
To: 58033@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>,
	"Lukasz Olszewski" <dev@lukaszolszewski.info>
Subject: bug#58033: PatchELF can create broken ELF binaries
Date: Sat, 11 Feb 2023 20:43:28 +0100	[thread overview]
Message-ID: <cc958f45-9e50-5761-4f52-7f6a22eef4e7@telenet.be> (raw)
In-Reply-To: <CACwB4R4Kj2cQseBKwr3kt_oz9u++2MZGdtboVzqLikk7Q4+HtQ@mail.gmail.com>


[-- Attachment #1.1.1: Type: text/plain, Size: 5503 bytes --]

I think I've found another instance of this bug.
Unlike <https://issues.guix.gnu.org/58033#0>, I'm getting an error 
message from validate-runpath, in the form of a type error.  Regardless 
of whether PatchELF's output is correct, I think there shouldn't be any 
type errors.

$ guix build -f guix.scm
[...]
validating RUNPATH of 1 binaries in 
"/gnu/store/cn7m18zrxp3ba8dxp6hy1w8jdr0kqp43-gearhead2-0.1/bin"...
error: in phase 'validate-runpath': uncaught exception:
wrong-type-arg "struct-vtable" "Wrong type argument in position ~A 
(expecting ~A): ~S" (1 "struct" #f) (#f)
phase `validate-runpath' failed after 0.0 seconds
Backtrace:
           18 (primitive-load "/gnu/store/ygpsgmga4qsp042z5nf9av4fm3y…")
In guix/build/gnu-build-system.scm:
     906:2 17 (gnu-build #:source _ #:outputs _ #:inputs _ #:phases . #)
In ice-9/boot-9.scm:
   1752:10 16 (with-exception-handler _ _ #:unwind? _ # _)
In srfi/srfi-1.scm:
     634:9 15 (for-each #<procedure 7fffeeb52420 at guix/build/gnu-b…> …)
In ice-9/boot-9.scm:
   1752:10 14 (with-exception-handler _ _ #:unwind? _ # _)
In guix/build/gnu-build-system.scm:
    927:23 13 (_)
    567:16 12 (validate-runpath #:validate-runpath? _ # _ #:outputs _)
In guix/build/utils.scm:
    677:23 11 (loop ("/gnu/store/cn7m18zrxp3ba8dxp6hy1w8jdr0kqp43-g…") …)
    677:23 10 (loop ("/gnu/store/cn7m18zrxp3ba8dxp6hy1w8jdr0kqp43-g…") …)
In guix/build/gremlin.scm:
     355:2  9 (validate-needed-in-runpath "/gnu/store/cn7m18zrxp3ba8…" …)
In ice-9/boot-9.scm:
   1752:10  8 (with-exception-handler _ _ #:unwind? _ # _)
In guix/build/gremlin.scm:
    368:20  7 (_)
    228:20  6 (elf-dynamic-info #<<elf> bytes: #vu8(127 69 76 70 2 1 …>)
In srfi/srfi-1.scm:
    586:17  5 (map1 (#<<dynamic-entry> type: 29 value: 905 offset:…> …))
In guix/build/gremlin.scm:
    189:32  4 (interpret-dynamic-entry #<<dynamic-entry> type: 29 val…>)
    166:14  3 (vma->offset #<<elf> bytes: #vu8(127 69 76 70 2 1 1 0 …> …)
In ice-9/boot-9.scm:
   1685:16  2 (raise-exception _ #:continuable? _)
   1683:16  1 (raise-exception _ #:continuable? _)
   1685:16  0 (raise-exception _ #:continuable? _)

ice-9/boot-9.scm:1685:16: In procedure raise-exception:
In procedure struct-vtable: Wrong type argument in position 1 (expecting 
struct): #f
builder for 
`/gnu/store/3x0bsdyczsxjhmwynvb3mgh5x75i88s4-gearhead2-0.1.drv' failed 
with exit code 1

The file "guix.scm" contains the following (remember to comment-out 
#:strip-binaries? #false) (while there is a (license #f) line, that's 
just because I didn't fill everything in yet; the software is actually 
free):


(use-modules (guix gexp) (guix packages) (guix build-system gnu) (guix 
utils) (guix hash) (gnu packages pascal)
   (gnu packages sdl) (gnu packages elf))

(define (fpc-compilation-options)
   ;; -P and -T needs to be set for cross-compilation
   #~`(#$(cond ((target-aarch64?) "-Paarch64")
               ((target-ppc32?) "-Ppowerpc")
               ((target-ppc64le?) "-Ppowerpc64")
               ((target-x86-64?) "-Px86_64")
               ((target-x86-32?) "-Pi386")
               ((target-arm32?) "-Parm")
               (#true (error "unrecognised cross-compilation target")))
       #$(cond ((target-linux?) "-Tlinux")
               ((target-hurd?) "-Tlinux") ; untested, hopefully it's 
close enough
               (#true (error "unrecognised cross-compilation target")))
       "-O2" ; do some optimisations
       ;; Let fpc find libraries.
       ,@(append-map (lambda (x)
                       (list (string-append "-Fl" x) ; fpc's equivalent 
of -L
                             (string-append "-Xr" x))) ; equivalent of 
-Wl,rpath
                     (string-split (getenv #$(if (%current-target-system)
                                                 "CROSS_LIBRARY_PATH"
                                                 "LIBRARY_PATH")) #\:))))

(package
   (name "gearhead2")
   (version "0.1") ; TODO
   (build-system gnu-build-system)
   (source (local-file "../gearhead-2" #:recursive? #true
                       #:select? (negate vcs-file?)))
   (arguments
     (list #:modules `((srfi srfi-1) ,@%gnu-build-system-modules)
           ;; #:strip-binaries? #true causes type errors in 
validate-runpath,
           ;; see <https://issues.guix.gnu.org/58033>.
           #:strip-binaries? #false ; strip-binaries? #true causes type 
errors in
           #:phases
           #~(modify-phases %standard-phases
               (delete 'configure)
               (replace 'build
                 (lambda _
                   (apply invoke "fpc" "gearhead2" 
#$(fpc-compilation-options))
                   ;; XXX: somehow the -Xr in fpc-compilation-options has no
                   ;; effect.  Work-around this.
                   (invoke "patchelf" "--set-rpath"
                           (getenv #$(if (%current-target-system)
                                         "CROSS_LIBRARY_PATH"
                                         "LIBRARY_PATH"))
                           "gearhead2")))
               (delete 'check) ; no test suite exists
               (replace 'install
                 (lambda _
                   (install-file "gearhead2" (string-append #$output 
"/bin")))))))
   (native-inputs (list patchelf fpc))
   (inputs (list sdl sdl-image sdl-ttf))
   (synopsis #f)
   (description #f)
   (home-page #f)
   (license #f))



[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 929 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

      parent reply	other threads:[~2023-02-11 19:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23 22:28 bug#58033: A bug in file-dynamic-info used by validate-runpath in gnu-build-system and others Lukasz Olszewski
2022-09-24 11:23 ` Lukasz Olszewski
2022-09-24 12:04   ` Lukasz Olszewski
2022-09-24 17:01 ` Lukasz Olszewski
2022-09-24 21:37   ` Lukasz Olszewski
2022-09-25 11:27 ` Lukasz Olszewski
2022-10-07  8:31   ` Ludovic Courtès
2023-02-11 19:43 ` Maxime Devos [this message]

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

  List information: https://guix.gnu.org/

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

  git send-email \
    --in-reply-to=cc958f45-9e50-5761-4f52-7f6a22eef4e7@telenet.be \
    --to=maximedevos@telenet.be \
    --cc=58033@debbugs.gnu.org \
    --cc=dev@lukaszolszewski.info \
    --cc=ludo@gnu.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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.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).