Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 716212 - dev-lang/icon-9.5.1-r2 : fpoll.c: error: dereferencing pointer to incomplete type FILE {aka struct _IO_FILE}
Summary: dev-lang/icon-9.5.1-r2 : fpoll.c: error: dereferencing pointer to incomplete ...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo musl team
URL:
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2020-04-04 18:16 UTC by Toralf Förster
Modified: 2020-06-04 13:35 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge-info.txt (emerge-info.txt,16.55 KB, text/plain)
2020-04-04 18:16 UTC, Toralf Förster
Details
dev-lang:icon-9.5.1-r2:20200404-173717.log (dev-lang:icon-9.5.1-r2:20200404-173717.log,19.45 KB, text/plain)
2020-04-04 18:16 UTC, Toralf Förster
Details
emerge-history.txt (emerge-history.txt,317.81 KB, text/plain)
2020-04-04 18:17 UTC, Toralf Förster
Details
environment (environment,91.11 KB, text/plain)
2020-04-04 18:17 UTC, Toralf Förster
Details
etc.portage.tbz2 (etc.portage.tbz2,25.45 KB, application/x-bzip)
2020-04-04 18:17 UTC, Toralf Förster
Details
temp.tbz2 (temp.tbz2,24.65 KB, application/x-bzip)
2020-04-04 18:17 UTC, Toralf Förster
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Toralf Förster gentoo-dev 2020-04-04 18:16:52 UTC
x86_64-gentoo-linux-musl-gcc -O2 -pipe -march=native -fno-strict-aliasing -fwrapv -fPIC -c fpoll.c
fpoll.c: In function fpoll:
fpoll.c:70:9: error: dereferencing pointer to incomplete type FILE {aka struct _IO_FILE}
   70 |    if (f->_cnt > 0)
      |         ^~
make[3]: *** [Makefile:15: fpoll.o] Error 1

  -------------------------------------------------------------------

  This is an unstable amd64 chroot image at a tinderbox (==build bot)
  name: 17.0_musl-20200328-141627

  -------------------------------------------------------------------

gcc-config -l:
 [1] x86_64-gentoo-linux-musl-9.3.0 *
clang version 10.0.0 
Target: x86_64-gentoo-linux-musl
Thread model: posix
InstalledDir: /usr/lib/llvm/10/bin
/usr/lib/llvm/10
10.0.0
Available Python interpreters, in order of preference:
  [1]   python3.8
  [2]   python3.7
  [3]   python3.6
  [4]   python2.7 (fallback)
Available Ruby profiles:
  [1]   ruby24 (with Rubygems)
  [2]   ruby25 (with Rubygems) *
Available Rust versions:
  [1]   rust-1.42.0 *
The following VMs are available for generation-2:

timestamp of HEAD at this tinderbox image:
/var/db/repos/gentoo	Sat Apr  4 17:07:58 UTC 2020
/var/db/repos/musl	Sat Apr  4 03:02:24 UTC 2020

emerge -qpvO dev-lang/icon
[ebuild  N    ] dev-lang/icon-9.5.1-r2  USE="-X -iplsrc"
Comment 1 Toralf Förster gentoo-dev 2020-04-04 18:16:55 UTC
Created attachment 630068 [details]
emerge-info.txt
Comment 2 Toralf Förster gentoo-dev 2020-04-04 18:16:58 UTC
Created attachment 630070 [details]
dev-lang:icon-9.5.1-r2:20200404-173717.log
Comment 3 Toralf Förster gentoo-dev 2020-04-04 18:17:00 UTC
Created attachment 630072 [details]
emerge-history.txt
Comment 4 Toralf Förster gentoo-dev 2020-04-04 18:17:04 UTC
Created attachment 630074 [details]
environment
Comment 5 Toralf Förster gentoo-dev 2020-04-04 18:17:06 UTC
Created attachment 630076 [details]
etc.portage.tbz2
Comment 6 Toralf Förster gentoo-dev 2020-04-04 18:17:09 UTC
Created attachment 630078 [details]
temp.tbz2
Comment 7 Cheyenne Wills 2020-04-09 15:03:50 UTC
I will need to discuss this problem with upstream owner of Icon to see if we can come up with a solution.

Question. Is there a way to detect if the sys-libs/musl library is being used?

The code that is failing is sensitive to the internal layout of the FILE structure, so there is a possibility that the particular function may not be supported with building with sys-libs/musl.  

One possible solution which would be Gentoo specific patch where a build time flag is defined.  I think I see what needs to be done within the code to handle musl's implementation of FILE, it's just figuring out how to detect that musl is being used.


The function (fpoll) is part of the Icon Program Library and can be viewed as an optional function (i.e. it's not part of the core language), so the other alternative is to detect the use of sys-libs/musl and just skip building that one function.
Comment 8 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2020-04-09 15:09:06 UTC
(In reply to Cheyenne Wills from comment #7)
> I will need to discuss this problem with upstream owner of Icon to see if we
> can come up with a solution.
> 
> Question. Is there a way to detect if the sys-libs/musl library is being
> used?
> 
> The code that is failing is sensitive to the internal layout of the FILE
> structure, so there is a possibility that the particular function may not be
> supported with building with sys-libs/musl.  
> 
> One possible solution which would be Gentoo specific patch where a build
> time flag is defined.  I think I see what needs to be done within the code
> to handle musl's implementation of FILE, it's just figuring out how to
> detect that musl is being used.
> 
> 
> The function (fpoll) is part of the Icon Program Library and can be viewed
> as an optional function (i.e. it's not part of the core language), so the
> other alternative is to detect the use of sys-libs/musl and just skip
> building that one function.

The musl developers have an objection on principle to a macro specifically for musl:
https://wiki.musl-libc.org/faq.html#Q:_Why_is_there_no_%3Ccode%3E__MUSL__%3C/code%3E_macro?

So, the usual approach is to look specifically whether or not the feature/macro/whatever
you need exists. Sometimes it does exist in Musl but in a different header, and sometimes not at all - here you will need to either disable the functionality or copy in the relevant parts yourself, or make use of some of the 'standalone' libraries that we've got in Gentoo for these situations:

https://wiki.gentoo.org/wiki/User:Sam_c/Musl_porting_notes#Standalone_packages

Hope that helps a bit. I haven't investigated FILE here though so maybe there is something
obvious I haven't commented on.
Comment 9 Cheyenne Wills 2020-04-09 20:03:49 UTC
(In reply to Sam James (sec padawan) from comment #8)

> The musl developers have an objection on principle to a macro specifically
> for musl:
> https://wiki.musl-libc.org/faq.html#Q:_Why_is_there_no_%3Ccode%3E__MUSL__%3C/
> code%3E_macro?

Yeah.. I saw that...

> 
> So, the usual approach is to look specifically whether or not the
> feature/macro/whatever
> you need exists. Sometimes it does exist in Musl but in a different header,
> and sometimes not at all - here you will need to either disable the
> functionality or copy in the relevant parts yourself, or make use of some of
> the 'standalone' libraries that we've got in Gentoo for these situations:
> 
> https://wiki.gentoo.org/wiki/User:Sam_c/
> Musl_porting_notes#Standalone_packages
> 
> Hope that helps a bit. I haven't investigated FILE here though so maybe
> there is something
> obvious I haven't commented on.

The problem isn't a missing macro.  The code is looking at some members within the FILE structure itself (which I guess is technically a "no-no") to determine if there is data "waiting".  

Probably the best bet is for a Gentoo specific patch and update the ebuild to pass a build parameter that can be tested.

I'll try to work on it this weekend
Comment 10 Cheyenne Wills 2020-05-05 16:17:15 UTC
I have a possible update, but it needs to be tested with a system where sys-libs/musl is installed. (which I currently don't have).

The update is currently in my github clone of the gentoo repo.  I'm just wondering
how I should proceed.

Thanks.
Comment 11 Michael 'veremitz' Everitt 2020-05-06 11:02:48 UTC
(In reply to Cheyenne Wills from comment #10)
> I have a possible update, but it needs to be tested with a system where
> sys-libs/musl is installed. (which I currently don't have).
> 
> The update is currently in my github clone of the gentoo repo.  I'm just
> wondering
> how I should proceed.
> 
> Thanks.

If you don't mind sharing the URL, I'm happy to do some testing on my systems.
Comment 12 Cheyenne Wills 2020-05-07 01:37:32 UTC
(In reply to Michael 'veremitz' Everitt from comment #11)
> (In reply to Cheyenne Wills from comment #10)
> > I have a possible update, but it needs to be tested with a system where
> > sys-libs/musl is installed. (which I currently don't have).
> > 
> > The update is currently in my github clone of the gentoo repo.  I'm just
> > wondering
> > how I should proceed.
> > 
> > Thanks.
> 
> If you don't mind sharing the URL, I'm happy to do some testing on my
> systems.

Thanks for the offer. With the help from some folks on IRC I was able to set up a chroot with the musl stage3 and was able to test the fix.

I've created the pull request (that is now referenced in the ticket).

Turned out that the way musl works, the internals of the FILE structure are "hidden", however there is a function (__freadahead) that musl makes available that performs the check that was needed. 

PS.. sorry about the couple of misfired commits in the PR.  I needed to gpg sign the commit and then I needed to  add additional fields to the commit message.

The pull request contains an additional update to the ebuild that fixes a problem where the CFLAGS set by the ebuild were not being used by the actual build (thus the -r3 on the ebuild).
Comment 13 Cheyenne Wills 2020-05-07 02:17:24 UTC
Also cleaned up whitespace/indentation
Comment 14 Cheyenne Wills 2020-05-11 14:50:32 UTC
Upstream has accepted adding the test and code to support the musl library in fpoll.c.

Will probably be a while before the change shows up in a published release so the patch file will be needed until then.
Comment 15 Larry the Git Cow gentoo-dev 2020-06-04 13:35:32 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ee19109f17c12e97eea26c8506538eb246de32ee

commit ee19109f17c12e97eea26c8506538eb246de32ee
Author:     Cheyenne Wills <cwills@witznd.net>
AuthorDate: 2020-05-18 04:48:10 +0000
Commit:     Joonas Niilola <juippis@gentoo.org>
CommitDate: 2020-06-04 13:34:37 +0000

    dev-lang/icon: fix for building with sys-libs/musl
    
    The Icon Programming Library function fpoll.c fails to build when
    the sys-libs/musl is being used.
    
    fpoll.c is sensitive to the internal layout of the FILE structure.
    
    Patch fpoll.c so it will build when sys-libs/musl is used.
    
    Since the musl library does not provide a way to detect that the
    musl library is being used. Update the ebuild to update CFLAGS
    to include a define that indicates musl is being used.
    
    In addition, CFLAGS were being overridden within the build process.
    Update the ebuild to ensure that the ebuild's CFLAGS are used.
    
    Closes: https://bugs.gentoo.org/716212
    Signed-off-by: Cheyenne Wills <cwills@witznd.net>
    Signed-off-by: Joonas Niilola <juippis@gentoo.org>

 dev-lang/icon/files/icon-9.5.1-musl.patch | 24 ++++++++++++++++++++++++
 dev-lang/icon/icon-9.5.1-r2.ebuild        | 12 +++++++++++-
 2 files changed, 35 insertions(+), 1 deletion(-)