Menu

#426 Building ipmitool 1.8.16 on Alpine Linux - fatal error: asm/socket.h: No such file or directory

version-1.8.17
closed-fixed
None
5
2016-04-12
2016-03-04
No

When building ipmitool 1.8.16 on Alpine Linux, the build fails:

imbapi.c:100:24: fatal error: asm/socket.h: No such file or directory

Apparently configure.ac does not check for the presence of that file and imbapi.c then just blindly assumes its presence.

You should be able to reproduce using following Dockerfile:

FROM alpine:latest
RUN apk -U add curl file gcc libgcc libc-dev make automake autoconf libtool
COPY build.sh .
RUN ./build.sh

And build.sh:

#!/bin/bash

set -e
set -x

PN=ipmitool
PV=1.8.16
P="${PN}-${PV}"

SRC_URI="http://downloads.sourceforge.net/project/${PN}/${PN}/${PV}/${P}.tar.bz2"
SHA256SUM=3c5da6b067abf475bc24685120ec79f6e4ef6b3ea606aaa267e462023861223e

S="${PWD}/${P}"

A="${SRC_URI##*/}"

curl -L -o "${A}" "${SRC_URI}"

echo "${SHA256SUM}  ${A}" | sha256sum -c

tar -xjf "${A}"

cd "${S}"
./configure LDFLAGS=-static
make

Discussion

  • Dennis Schridde

    Dennis Schridde - 2016-03-04

    There are three more errors, which I overlooked initially:

    In file included from imbapi.c:99:0:
    imbapi.h:51:17: error: conflicting types for 'wchar_t'
     typedef long    wchar_t;
                     ^
    
    imbapi.c: In function 'MapPhysicalMemory':
    imbapi.c:109:19: error: 'EXEC_PAGESIZE' undeclared (first use in this function)
     # define PAGESIZE EXEC_PAGESIZE
                       ^
    imbapi.c:2003:30: note: in expansion of macro 'PAGESIZE'
      diff = (int)startpAddress % PAGESIZE;
                                  ^
    
    imbapi.c: In function 'UnmapPhysicalMemory':
    imbapi.c:110:19: error: 'EXEC_PAGESIZE' undeclared (first use in this function)
     # define PAGESIZE EXEC_PAGESIZE
                       ^
    imbapi.c:2049:44: note: in expansion of macro 'PAGESIZE'
      diff =  ((unsigned int) virtualAddress) % PAGESIZE;
                                                ^
    

    Attached patches fix all of them, including the originally reported one.

    All patches and build scripts are also available on GitHub: https://github.com/urzds/ipmitool-docker

     
    • Zdenek Styblik

      Zdenek Styblik - 2016-03-04

      Hello,

      all attached files have 0 Bytes. Also, I don't understand why you do compile IMB (API) on Linux since it's a Windows thing.

      Z.

       
      • Dennis Schridde

        Dennis Schridde - 2016-03-04

        all attached files have 0 Bytes

        Weird... Neither my browser nor SF complained about that. (The files on disk are not empty.)

        I don't understand why you do compile IMB (API) on Linux since it's a Windows thing

        I did not decide to do that. In fact I have no clue what IMB is and just ran ./configure && make.

        There are definitely Linux specific portions in the code, which is why I never noticed that it is Windows only. E.g. imbapi.c:223: #else /* LINUX, SCO_UW, etc. */

         

        Last edit: Dennis Schridde 2016-03-04
        • Zdenek Styblik

          Zdenek Styblik - 2016-03-04

          You must run bootstrap first.

           
          • Dennis Schridde

            Dennis Schridde - 2016-03-04

            The release tarball I downloaded contains no such file:

            # cd ipmitool-1.8.16
            # ls
            aclocal.m4  AUTHORS  ChangeLog  compile*  config.guess*  config.h.in  config.sub*  configure*  configure.ac  contrib/  control/  COPYING  depcomp*  doc/  include/  install-sh*  ipmitool.spec  lib/  ltmain.sh  Makefile.am  Makefile.in  missing*  README  src/
            
             
            • Zdenek Styblik

              Zdenek Styblik - 2016-03-04

              I see and I don't know what else to say than: well, that sucks :-s

               
  • Dennis Schridde

    Dennis Schridde - 2016-03-06

    I added a little bit of error handling to the PAGESIZE patch.

     
    • Zdenek Styblik

      Zdenek Styblik - 2016-03-07

      Hello,

      some comments on my side:

      Please, let me know.

      Thanks,
      Z.

       

      Last edit: Zdenek Styblik 2016-03-07
  • Dennis Schridde

    Dennis Schridde - 2016-03-10

    I will prepare a branch during the next days. Please give me some time - there seem to be some more potential bugs that I would like to fix.

     
    • Zdenek Styblik

      Zdenek Styblik - 2016-03-10

      Sure, no problem. No pressure.
      btw I'm not sure if it makes sense to fix errors which are caused by not running bootstrap, resp. commands in it(as far as my understanding goes, it's necessary to setup environment/configure) On the other hand, I don't know what exactly you're fixing.
      Also, if you have any questions or need to discuss something, please, post a message here.

      Z.

       
    • Zdenek Styblik

      Zdenek Styblik - 2016-04-10

      Hello, any progress?

       
  • Dennis Schridde

    Dennis Schridde - 2016-04-11

    I submitted merge-request #10: https://sourceforge.net/p/ipmitool/source/merge-requests/10/

    Merge-request #11 contains even more fixes, but those only fix the most suspicious warnings: https://sourceforge.net/p/ipmitool/source/merge-requests/11/
    I did not fix all warnings and the type-punning warnings in particular should be looked at. Sadly I didn't have time to do that, yet. Would be great if at some point the whole tool would compile without warnings.

     

    Last edit: Dennis Schridde 2016-04-11
    • Zdenek Styblik

      Zdenek Styblik - 2016-04-11

      Hello Dennis,

      I've reviewed PR/MR#10. Please, could we do without #ifdef for PAGESIZE? It's part of POSIX.1, so it really should be available and no checks should be required. I mean, POSIX.1 is 15 years old now. Thoughts?

      I will give a look to the other PR/MR tomorrow. But it seems it contains commits from the previous PR/MR. Is this correct?

      Thanks,
      Z.

       
      • Dennis Schridde

        Dennis Schridde - 2016-04-12

        Well, one of the original problems was this:

        imbapi.c: In function 'MapPhysicalMemory':
        imbapi.c:109:19: error: 'EXEC_PAGESIZE' undeclared (first use in this function)
         # define PAGESIZE EXEC_PAGESIZE
                           ^
        

        So PAGESIZE was not defined. sysconf(3) says one should check how to determine the value of this using the method described in posixoptions(7). But the latter does not mention PAGESIZE at all. Thus I opted for substituting the test for _POSIX_PAGESIZE==-1,0, at compile time (as described by posixoptions(7) for the general case) with a test for the existence of PAGESIZE (as posixoptions(7) fails to define POSIX_PAGESIZE, as it does for many other _SC options). If you have a better suggestion, please tell me.

        PR#11 indeed builds on top of PR#10, as the fixes there are needed to get ipmitool to compile at all. I would be unable to test PR#11 on its own, thus I opted not to rebase it onto master (instead of letting it live on top of PR#10).

         
        • Dennis Schridde

          Dennis Schridde - 2016-04-12

          As to why PAGESIZE might be not be defined by posixoptions(7), I cite getpagesize(2):

          Whether getpagesize() is present as a Linux system call depends on the architecture. If it is, it returns the kernel symbol PAGE_SIZE, whose value depends on the architecture and machine model. Generally, one uses binaries that are dependent on the architecture but not on the machine model, in order to have a single binary distribution per architecture. This means that a user program should not find PAGE_SIZE at compile time from a header file, but use an actual system call, at least for those architectures (like sun4) where this dependency exists. Here libc4, libc5, glibc 2.0 fail because their getpagesize() returns a statically derived value, and does not use a system call. Things are OK in glibc 2.1.
          

          So according to that, it makes no sense at all to determine PAGESIZE at compile time, which is why I originally replaced it with a call to sysconf(_SC_PAGESIZE) as described in getpagesize(2), and did not bother to guard it with #ifdef.

          When I added the #ifdefs according to point 3 of your comment from 2016-03-07, I was assuming you needed a code path that uses plain old PAGESIZE (without sysconf) for pre-POSIX.1 legacy systems.

           

          Last edit: Dennis Schridde 2016-04-12
          • Zdenek Styblik

            Zdenek Styblik - 2016-04-12

            Uh-huh. I'm a bit confused. I meant to use sysconf(_SC_PAGESIZE) or sysconf(PAGESIZE) and drop whole #ifdef thing.

             
            • Dennis Schridde

              Dennis Schridde - 2016-04-12

              Ok, I misunderstood that.

              What is your understanding of this part of sysconf(3)?

                     For options, typically, there is a constant _POSIX_FOO that may be
                     defined in <unistd.h>.  If it is undefined, one should ask at run
                     time.  If it is defined to -1, then the option is not supported.  If
                     it is defined to 0, then relevant functions and headers exist, but
                     one has to ask at run time what degree of support is available.  If
                     it is defined to a value other than -1 or 0, then the option is
                     supported.  Usually the value (such as 200112L) indicates the year
                     and month of the POSIX revision describing the option.  Glibc uses
                     the value 1 to indicate support as long as the POSIX revision has not
                     been published yet.  The sysconf() argument will be _SC_FOO.  For a
                     list of options, see posixoptions(7).
              

              I read that as:

              1. Check whether _POSIX_PAGESIZE exist.
              2. If it does not, you need to use sysconf(_SC_PAGESIZE) to determine the value at run time.
              3. If it does and has the value -1, then PAGESIZE is not supported at all.
              4. If it has the value 0, you need to use sysconf(_SC_PAGESIZE) to determine the value at run time.
              5. If it has any other value, you can use PAGESIZE directly, as a compile time constant.

              As _POSIX_PAGESIZE does not exist at all, I understand that we need to use sysconf(_SC_PAGESIZE).

              The next paragraph again details this:

                     For variables or limits, typically, there is a constant _FOO, maybe
                     defined in <limits.h>, or _POSIX_FOO, maybe defined in <unistd.h>.
                     The constant will not be defined if the limit is unspecified.  If the
                     constant is defined, it gives a guaranteed value, and a greater value
                     might actually be supported.  If an application wants to take
                     advantage of values which may change between systems, a call to
                     sysconf() can be made.  The sysconf() argument will be _SC_FOO.
              

              IMO that kind of contradicts the previous paragraph. _PAGESIZE might contain an upper limit on the page size, but this paragraph also explains that _POSIX_PAGESIZE might do the same (but in the previous paragraph it was said that it would be defined to the POSIX version defining the constant).

              In any case, this paragraph again says that calls to sysconf() need to be made using _SC_PAGESIZE and not _PAGESIZE.

              sysconf(3p) (POSIX Programmer's Manual) again confirms that PAGESIZE and PAGE_SIZE should be queried using _SC_PAGESIZE and _SC_PAGE_SIZE, respectively.

              Thus I cannot find any evidence, that it would be allowed to call sysconf(PAGESIZE) or sysconf(PAGE_SIZE).

               

              Last edit: Dennis Schridde 2016-04-12
              • Zdenek Styblik

                Zdenek Styblik - 2016-04-12

                My reaction to this is: it's a mess;, but you're right and there unfortunately seems to be no way around it. Ok.

                 
                • Dennis Schridde

                  Dennis Schridde - 2016-04-12

                  I can change the commit to use only sysconf(_SC_PAGESIZE) (and fallback to sysconf(_SC_PAGE_SIZE), if _SC_PAGESIZE is not defined), just as I did initially (minus the < 0 bug, which was caused by only having in mind the generic parts of sysconf(3)).

                  Shall I do that?

                   

                  Last edit: Dennis Schridde 2016-04-12
                  • Zdenek Styblik

                    Zdenek Styblik - 2016-04-12

                    Let's leave it like this. I've merged both PRs. Thanks.

                     
  • Zdenek Styblik

    Zdenek Styblik - 2016-04-12
    • status: open --> closed-fixed
    • assigned_to: Zdenek Styblik
     
  • Dennis Schridde

    Dennis Schridde - 2016-04-12

    Thanks!

     

Log in to post a comment.