Skip to content

Build fix for Linux overlay with 03242016 compiler. #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2016

Conversation

dgrove-oss
Copy link
Contributor

With the 03242016 development drop, building the
Dispatch overlay on Linux fails because mode_t and
off_t are not defined. This is a minimal fix to
include the needed header files and get the build
working again.

@dgrove-oss
Copy link
Contributor Author

This fix is also included in #61, but since it may take some time for 61 to get merged and the Linux build of dispatch is broken without this small change opening a separate PR.

@dgrove-oss
Copy link
Contributor Author

Merged this changeset to experimental/foundation in #68. Leaving this pull request open and baking branch undeleted until a fix gets merged to the master branch to enable it to compile with 03242016 Swift tool chain.

@@ -32,6 +32,10 @@
#include <stdarg.h>
#include <unistd.h>
#include <fcntl.h>
#ifndef __APPLE__
#include <stdio.h>
Copy link
Contributor

@MadCoder MadCoder May 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need that in a public header? we kind of try to restrict what we export to a bare minimum, <sys/types.h> I understand, but stdio seems to point toward something else being wrong.

I would also add <sys/types.h> for everyone not only !__APPLE__ it's fine

@dgrove-oss
Copy link
Contributor Author

dgrove-oss commented May 12, 2016

Coming back to this, I'm actually not sure if this is really a bug that should be fixed by changing dispatch.h or by fixing the clang importer of swiftc or the module maps the importer is using for SwiftGLibc. This change is not for the C compilation of libdispatch. What it is trying to fix is a problem when compiling Dispatch.swift with a swift toolchain post the 03242016 drop. Namely:

libtool: compile:  clang -DHAVE_CONFIG_H -I. -I/home/dgrove/swift/swift-corelibs-libdispatch/src -I../config -I.. -I/home/dgrove/swift/swift-corelibs-libdispatch -I/home/dgrove/swift/swift-corelibs-libdispatch/private -I/home/dgrove/swift/swift-corelibs-libdispatch/os -I/home/dgrove/swift/swift-corelibs-libdispatch/libpwq/include -Wall -fvisibility=hidden -momit-leaf-frame-pointer -I/usr/include/kqueue -isystem /usr/include/bsd -DLIBBSD_OVERLAY -fblocks -g -O2 -c /home/dgrove/swift/swift-corelibs-libdispatch/src/swift/swift_wrappers.c  -fPIC -DPIC -o swift/.libs/swift_wrappers.o
/home/dgrove/swift/build/dpg/swift-linux-x86_64/bin/swiftc -Xcc -fmodule-map-file=/home/dgrove/swift/swift-corelibs-libdispatch/dispatch/module.map -I/home/dgrove/swift/swift-corelibs-libdispatch -parse-as-library -Xcc -fblocks -c -o /home/dgrove/swift/build/dpg/libdispatch-linux-x86_64/src/Dispatch.o /home/dgrove/swift/swift-corelibs-libdispatch/src/swift/Dispatch.swift
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "dispatch.h"
         ^
/home/dgrove/swift/swift-corelibs-libdispatch/dispatch/dispatch.h:59:10: note: in file included from /home/dgrove/swift/swift-corelibs-libdispatch/dispatch/dispatch.h:59:
#include <dispatch/io.h>
         ^
/home/dgrove/swift/swift-corelibs-libdispatch/dispatch/io.h:253:31: error: declaration of 'mode_t' must be imported from module 'SwiftGlibc.POSIX.sys.types' before it is required
        const char *path, int oflag, mode_t mode,
                                     ^
/usr/include/x86_64-linux-gnu/sys/types.h:70:18: note: previous declaration is here
typedef __mode_t mode_t;
                 ^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "dispatch.h"
         ^
/home/dgrove/swift/swift-corelibs-libdispatch/dispatch/dispatch.h:59:10: note: in file included from /home/dgrove/swift/swift-corelibs-libdispatch/dispatch/dispatch.h:59:
#include <dispatch/io.h>
         ^
/home/dgrove/swift/swift-corelibs-libdispatch/dispatch/io.h:355:2: error: declaration of 'off_t' must be imported from module 'SwiftGlibc.C.stdio' before it is required
        off_t offset,
        ^
/usr/include/stdio.h:90:17: note: previous declaration is here
typedef __off_t off_t;

Do you want to pull in someone from the compiler team to advise?

@MadCoder
Copy link
Contributor

off_t is supposed to be in <unistd.h> which is a more reasonnable header to import from dispatch.h IMO (for all platforms)

@dgrove-oss
Copy link
Contributor Author

Looks like the key bit (which other header file to try) got chopped from your comment.

@MadCoder
Copy link
Contributor

unistd.h stupid html sanitizer sigh

@dgrove-oss
Copy link
Contributor Author

Thanks. unistd.h is already #included. And as expected my unistd.h does include a definition of off_t. So I think maybe the fix is in the GLibc module map. Who would be the right person on the compiler team to drag in to help figure out why the importer isn't seeing the definition of off_t when it processes the header file (but was seeing it before the march 24 drop of the swift compiler).

@MadCoder
Copy link
Contributor

I don't know you should ask on one of the swift mailing lists. FWIW I don't think the dispatch build uses modules on linux, so I'm slightly surprised at the issue here.

@mwwa maybe you can help given the work you're doing on the overlay?

The types mode_t and off_t are conditionally defined in
multiple header files in GLibc.  This interacts poorly with
the clang module maps, resulting in it insisting that these types
should be imported from stdio.h (which we don't want to
unconditionally include in the dispatch API header files).
We can fix the clash with mode_t by including sys/types.h
early in the list of includes in dispatch.h.  I was unable to
find a similar fix for off_t, so instead this change
conditionally includes stdio.h in dispatch/io.h under a
preprocessor symbol that will only be defined when compiling
Dispatch.swift to build the swiftmodule for the overlay.
@dgrove-oss dgrove-oss force-pushed the fix-import-for-03242016-drop branch from 28128e1 to 2b2d15d Compare June 3, 2016 19:46
@dgrove-oss
Copy link
Contributor Author

@MadCoder I've played with various options suggested by @gribozavr on swift-dev list today, and I think this change is the least disruptive fix that is possible in the medium term (ie, without getting the system headers changed to be more module friendly). Hopefully guarding the include of stdio.h will make this attempt more acceptable than the previous one.

@MadCoder
Copy link
Contributor

MadCoder commented Jun 3, 2016

that looks reasonnable to me

@MadCoder MadCoder merged commit 954ace4 into swiftlang:master Jun 3, 2016
das pushed a commit that referenced this pull request Jun 14, 2016
Build fix for Linux overlay with 03242016 compiler.

Signed-off-by: Daniel A. Steffen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants