Red Hat Bugzilla – Bug 473947
asm-generic/ioctl.h can generate link error undefined __invalid_size_argument_for_IOC
Last modified: 2015-05-04 21:15:59 EDT
Created attachment 325241 [details]
Reproducer source code for this bug
Description of problem:
This is actually an issue with the kernel-headers package, the file
This has been resolved in the upstream kernel, see:
The Fedora10 kernel-headers already includes this commit.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
Building a program with debug (-g flag) can result in undefined reference to
This code from include/asm-generic/ioctl.h is the culprit:
50 /* provoke compile error for invalid uses of size argument */
51 extern unsigned int __invalid_size_argument_for_IOC;
52 #define _IOC_TYPECHECK(t) \
53 ((sizeof(t) == sizeof(t) && \
54 sizeof(t) < (1 << _IOC_SIZEBITS)) ? \
55 sizeof(t) : __invalid_size_argument_for_IOC)
61 #define _IOWR(type,nr,size)
This gets used in the various _IO definitions. The comment indicates this was
intended to throw a compiler error. It doesn't - it will always compile and
end up generating a link-error for an undefined reference to
In fact, lines 51-55 will only work *if* the compiler always optimizes away the
reference to __invalid_size_argument_for_IOC. It turns out that gcc
(currently) actually does optimize this out in all cases (even -g -O0), and
never generates the undefined link reference.
This isn't true for Intel's compilers (icc and icpc). If the -g flag is
asserted the reference is generated and the error *always* occurs. It's hard
to generate a debug image; The work-around hack is ugly - add a global def for
__invalid_size_argument_for_IOC. This also disables the test. The intel
compiler might not be the only one that has this behaviour.
Steps to reproduce:
I've attached a short reproducer program.
(OK) gcc -Wall ioctl_broke.c
(OK) gcc -g -Wall ioctl_broke.c
(OK) icc -Wall ioctl_broke.c
(Breaks) icc -g -Wall ioctl_broke.c
/tmp/iccRFH4Pa.o: In function `main':
/home/rda/ioctl_test.c:23: undefined reference to '__invalid_size_argument_for_IOC'
BTW - I posted this here to document for other users, and the upstream patch (#ifdefs so it only does the check when building the kernel) seems like it could be readily applied to the RHEL5 kernel without impact.
Hi Bob - I have patched build but I do not have Intel compiler. Can you please test my rpms? Which ARCH do you have? Thanks.
I have a i386 box running kernel-2.6.18-92.el5.i686.rpm (RHEL 5.2) available. Would this just be a kernel-headers update, or would all of kernel + kernel-devel + kernel-headers need to be installed?
kernel, kernel-devel and kernel-headers packages for this bz are here:
It should be sufficient to install only kernel-headers. But try yourself.
Thanks, this works with just the kernel-headers update. It looks like RHEL update 5.3 just went out. Will this be available as an update before 5.4? I'd like to reflect when the patch goes out in our internal bug tracking system (we've logged a couple of minor build bugs that tie back to this issue).
Bob, well, I'm afraid this will most likely not be available before 5.4.
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release. Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products. This request is not yet committed for inclusion in an Update
Updating PM score.
You can download this test kernel from http://people.redhat.com/dzickus/el5
Please do NOT transition this bugzilla state to VERIFIED until our QE team
has sent specific instructions indicating when to do so. However feel free
to provide a comment indicating that this fix has been verified.
We've verified that kernel-2.6.18-135.el5 fixes this issue.
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.