cffi cannot open GNU ld scripts.

Bug #941257 reported by Pascal J. Bourguignon
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
CFFI
Triaged
High
Unassigned

Bug Description

On Gentoo 64-bit, a lot of /usr/lib/lib*.so are actually GNU ld scripts, redirecting to the actual ELF libraries in /lib64.

Here is a proposed function to read them when the library cannot be opened, and redirect to the true library:

(defun load-foreign-library-if-gnu-ld-script (libname libpath error)
  (let ((newpath
         (with-open-file (stream libpath
                                 :direction :input
                                 :element-type 'character
                                 :external-format :default
                                 :if-does-not-exist nil)
           (when stream
             (let ((buffer (make-array 80
                                       :element-type 'character
                                       :fill-pointer 80)))
               (setf (fill-pointer buffer) (read-sequence buffer stream))
               (when (search "GNU ld script" buffer)
                 (file-position stream 0)
                 (loop
                   (let ((line (read-line stream nil nil)))
                     (cond
                       ((null line) (return nil))
                       ((and (< 5 (length line))
                             (string= "GROUP" (subseq line 0 5)))
                        (let* ((left (position #\( line))
                               (ppos (and left (position #\space line
                                                          :start (1+ left)
                                                          :test (function char/=))))
                               (right (and ppos (position #\space line :start ppos))))
                          (return
                            (and right (subseq line ppos right))))))))))))))
    (if newpath
        (cffi::%load-foreign-library libname newpath)
        (error error))))

In load-foreign-library-path, the two calls to %load-foreigh-library could be replaced by:

  (handler-case (cffi::%load-foreign-library name path)
    (error (err)
      (LOAD-FOREIGN-LIBRARY-IF-GNU-LD-SCRIPT name path err)))

Revision history for this message
Luís Oliveira (luismbo) wrote :

Thanks for your bug report. Do you have any information on how to create these scripts so I can test your function locally and perhaps add a new test to the suite? A quick search for "ld scripts" didn't find much.

Changed in cffi:
status: New → Triaged
importance: Undecided → High
Revision history for this message
Pascal J. Bourguignon (pjb-informatimago) wrote : Re: [Bug 941257] Re: cffi cannot open GNU ld scripts.

On 2012/03/04, at 19:26 , Luís Oliveira wrote:

> Thanks for your bug report. Do you have any information on how to create
> these scripts so I can test your function locally and perhaps add a new
> test to the suite? A quick search for "ld scripts" didn't find much.

Here is /usr/lib/libncurses.so on my gentoo system:

>

The documentation of GNU ld can be found there:

http://sourceware.org/binutils/docs/ld/index.html

And specifically the GROUP command:

http://sourceware.org/binutils/docs/ld/File-Commands.html#index-GROUP_0028_0040var_007bfiles_007d_0029-357

--
__Pascal Bourguignon__
http://www.informatimago.com

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.