On Thu, 08 Oct 2020 16:26:19 -0400,
Ashley Dixon wrote:
> 
> [1  <text/plain; us-ascii (quoted-printable)>]
> On Thu, Oct 08, 2020 at 01:55:04PM -0400, John Covici wrote:
> > modules.alias              modules.builtin
> > modules.builtin.bin        modules.dep.bin            modules.order
> > modules.symbols
> > modules.alias.bin          modules.builtin.alias.bin  modules.dep
> > modules.devname            modules.softdep
> > modules.symbols.bin
> 
> That's fine.
> 
> > and the error message is
> > 
> > lspci: Unable to load libkmod resources: error -12
> 
> That error message is printed by lspci [1], although it is  the  result  of  
> the
> libkmod `kmod_load_resources` function returning less than zero [2].  With a 
> -12
> error, this suggests a failing with the `index_mm_open` function [3]. It's 
> quite
> a beast of a function; the failure could be due to a multitude of reasons.
> 
> Considering the nature of the error (memory allocation  failure),  I  reckon  
> it
> must be either the following call to mmap(2), or the preceding call to  
> open(2):
> (paraphrasing for formatting):
> 
> 
>       if ((fd = open(filename, O_RDONLY|O_CLOEXEC)) < 0) {
>               DBG(ctx, "open(%s, O_RDONLY|O_CLOEXEC): %m\n", filename);
>               err = -errno;
>               goto fail_open;
>       }
> 
>         /* [...] */
> 
>       if ( ( idx->mm = mmap ( NULL, st.st_size, PROT_READ,
>                                         MAP_PRIVATE, fd, 0 ) ) == MAP_FAILED) 
> {
>               ERR(ctx, "mmap (NULL, %"PRIu64", PROT_READ, %d, " \
>                                 "MAP_PRIVATE, 0 ): %m\n", st.st_size, fd);
>               err = -errno;
>               goto fail_nommap;
>       }
> 
> I might you need to debug this on your machine, as I can't reproduce it  
> myself.
> You'll need to clone, recompile,  and  relink  libkmod  and  pciutils  with  
> the
> maximum debugging settings, to keep all symbols in  the  executable.   I  
> assume
> you're using GCC, although I suspect the same should work with Clang.
> 
> git clone both repos: [4] and [5].
> 
> libkmod:
>         - Save the old symlink, by renaming /lib64/libkmod.<version> to
>           something temporary, like libkmod.old.
>         - Execute ./autogen.sh to create a configure script.
>         - Run the configure script to enable maximum debugging:
>                 ./configure CFLAGS='-ggdb3' --prefix=/usr --sysconfdir=/etc \
>                 --libdir=/usr/lib64 --with-rootprefix= 
> --with-rootlibdir=/lib64
>         - Compile and install the shared objects (you need to be root):
>                 make && make install
>         - Ensure the `make install` has recreated the major version symlink in
>           /lib64 to the new shared object file.
> 
> pciutils:
>         - Compile; there is no need to install:
>                 make CFLAGS="-ggdb3"
> 
> Now you have an lspci executable which is linked with the new libkmod, just 
> need
> to attach a debugger, such as gdb, and break on the troublesome function:
> 
>         $ gdb ./lspci
>         Reading symbols from ./lspci...
>         (gdb) b index_mm_open
>         Function "index_mm_open" not defined.
>         Make breakpoint pending on future shared library load? (y or [n]) y
>         Breakpoint 1 (index_mm_open) pending.
>         (gdb) run -k
> 
> ... after a while, you'll encounter the first invocation of the troublemaker:
> 
>         Breakpoint 1, index_mm_open (ctx=0x555555583340, 
> filename=0x7fffffffc920
>             "/lib/modules/5.4.60-gentoo/modules.dep.bin", 
> stamp=0x5555555833a0,
>             pidx=0x555555583378) at libkmod/libkmod-index.c:744
> 
> Before going any further, I want to confirm that  `filename`  does  point  to 
>  a
> correct file?  I doubt the open(2) call would fail with ENOMEM if the  file  
> was
> invalid, although you never know.  Assuming `filename` is valid,  we  can  
> start
> stepping through the function to determine which inner function is failing.   
> My
> bets are on mmap.
> 
> Hope to hear from you soon.
> 
> [1] 
> https://git.kernel.org/pub/scm/utils/pciutils/pciutils.git/tree/ls-kernel.c#n42
> [2] 
> https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/tree/libkmod/libkmod.c#n842
> [3] 
> https://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git/tree/libkmod/libkmod-index.c#n742
> [4] git://git.kernel.org/pub/scm/utils/pciutils/pciutils.git
> [5] git://git.kernel.org/pub/scm/utils/kernel/kmod/kmod.git
> 


Since I compile most packages with split-debug and my default flags
contain -gdb, could I use  the existing packages?

-- 
Your life is like a penny.  You're going to lose it.  The question is:
How do
you spend it?

         John Covici wb2una
         [email protected]

Reply via email to