[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MirageOS-devel] Compiling C components for mirage-xen



On Wed, Jan 13, 2016 at 2:17 AM, Daniel J Williams <djwillia@xxxxxxxxxx> wrote:
>
>> On Mon, Jan 11, 2016 at 9:48 PM, Thomas Leonard <talex5@xxxxxxxxx> wrote:
>> > On 11 January 2016 at 09:06, Tim Cuthbertson <tim@xxxxxxxxxxx> wrote:
>> >> On Mon, Jan 11, 2016 at 4:52 AM, Thomas Leonard <talex5@xxxxxxxxx>
>> >> wrote:
>> >>> On 10 January 2016 at 10:15, Tim Cuthbertson <tim@xxxxxxxxxxx> wrote:
>> >>>> On Fri, Jan 8, 2016 at 11:14 PM, Thomas Leonard <talex5@xxxxxxxxx>
>> >>>> wrote:
>> >>>>> On 8 January 2016 at 11:19, Tim Cuthbertson <tim@xxxxxxxxxxx> wrote:
>
>> >>>>>>  - I don't really know what the thing I'm doing is. Is mirage-xen a
>> >>>>>> different architecture? A different ABI? Do C libraries need to be
>> >>>>>> cross-compiled, or just compiled with particular flags so that
>> >>>>>> they'll
>> >>>>>> work on xen-minios instead of gnu/linux?
>> >>>>>
>> >>>>> C libraries need to be compiled with different headers and flags (in
>> >>>>> particular, -mno-red-zone). Using libraries compiled for Linux will
>> >>>>> often appear to work, but may fail when interrupts occur, so the
>> >>>>> build
>> >>>>> makes it hard to use them by accident.
>> >>>>>
>> >>>>> However, OCaml binaries can be shared (ocamlopt doesn't use a red
>> >>>>> zone
>> >>>>> and the OCaml ABI is the same).
>> >>>>>
>> >>>>>>  - The existing scripts seem to be pretty ad-hoc - zarith gets away
>> >>>>>> mainly with particular CFLAGS
>> >>>>>> (https://github.com/ocaml/opam-repository/blob/master/
>> packages/zarith-xen/zarith-xen.1.4/files/mirage-install.sh),
>> >>>>>
>> >>>>> It's using pkg-config to get the important flags. The others are
>> >>>>> optimisations (except -fno-builtin, which is either not needed or
>> >>>>> should be supplied by Mini-OS).
>> >>>>>
>> >>>>>> while gmp looks like a full cross-compilation using `--target` (and
>> >>>>>> then does some other sneaky things).
>> >>>>>>
>> >>>>>> safepass uses OASIS for its build system, which doesn't seem to
>> >>>>>> have
>> >>>>>> any cross-compilation functionality built in as far as I could
>> >>>>>> tell.
>> >>>>>> Can anyone give me pointers on what I'd need to do to safepass'
>> >>>>>> build
>> >>>>>> scripts to get this working in mirage-xen, or at the least some
>> >>>>>> clarification on why it doesn't work as-is and how cross
>> >>>>>> compilation
>> >>>>>> works for C libraries used in mirage-xen?
>
>
>> > Correct: Mirage on Xen does not use shared libraries. I don't know how
>> > to prevent them from being built. The easiest option might be to
>> > remove the uses of errno from the library (it doesn't look like the
>> > OCaml bindings do anything with it anyway).
>>
>> The ocaml bindings (bcrypt_stub.c) doesn't, but the C code compiled
>> with it (crypt_blowfish.c) does, so I can't just remove it sadly.
>>
>> So this is a bit ridiculous, but I did manage to get it compiling with
>> the following hack in the build script:
>>
>>   mkdir fake_libc
>>   echo '"fake_libc": -traverse' >> _tags
>>   touch fake_libc/libc.c
>>   gcc -shared -nostdlib -o fake_libc/libc.so fake_libc/libc.c
>>
>> (and also added -L$PWD/fake_libc to oasis' CCLib field)
>>
>
> I'm not sure if this will help, but I thought I'd share my
> "workaround" for compiling C files from Mirage components to link
> against Solo5(https://github.com/djwillia/solo5/tree/mirage), which
> you can think of as a layer like Mini-OS.
>
> The ability to send flags to C programs from OASIS seems a bit limited
> to me: I would have liked to specify the cross compiler, but I'm not
> sure if that's possible.  I don't really know what the right way to do
> this is, but I ended up adding a lot of CFLAGS from the kernel build:
>
>     CCOpt: -ffreestanding -mcmodel=large -mno-red-zone -mno-3dnow \
>            -std=gnu99 -O2 -Wall -Wextra -Werror -D__SOLO5__       \
>            -fno-PIC -g   -I/home/solo5/solo5/kernel
>
> ( see https://github.com/djwillia/mirage-block-solo5/blob/solo5/_oasis#L17 )
>
> Then I link against the resulting libmirage_block_solo5_stubs.a and
> all of the static libraries listed out from e.g., `pkg-config --static
> --libs mirage-xen`
>
> Dan

Thanks, Dan.

Does this prevent oasis from building a .so file of your library? I
think I've got similar CCOpt setting by using `pkg-config --static
--cflags mirage-xen-ocaml`, but my main issue is really that I've
found no CCLib options which can prevent oasis from trying to compile
a .so of my library against an incompatible libc.so.

Cheers,
 - Tim.

_______________________________________________
MirageOS-devel mailing list
MirageOS-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.