2014-10-20 08:42:34

by Markos Chandras

[permalink] [raw]
Subject: [PATCH] Documentation: ptp: Fix build failure on MIPS cross builds

The MIPS system calls are defined based on the -mabi gcc option.
However, the testptp is built on the host using the unistd header
from the kernel sources which were built for the MIPS architecture
thus guarded with the __MIPS_SIM_{ABI64, ABI32, NABI32} definitions
leading to the following build problem:

Documentation/ptp/testptp.c: In function 'clock_adjtime':
Documentation/ptp/testptp.c:55: error: '__NR_clock_adjtime'
undeclared (first use in this function)
Documentation/ptp/testptp.c:55: error: (Each undeclared identifier is reported
only once Documentation/ptp/testptp.c:55: error: for each function it appears in.)

This fix is similar to e9107f88c985bcda ("samples/seccomp/Makefile: do not build
tests if cross-compiling for MIPS")

Cc: Richard Cochran <[email protected]>
Cc: Jonathan Corbet <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Markos Chandras <[email protected]>
---
Documentation/ptp/Makefile | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/Documentation/ptp/Makefile b/Documentation/ptp/Makefile
index 293d6c09a11f..397c1cd2eda7 100644
--- a/Documentation/ptp/Makefile
+++ b/Documentation/ptp/Makefile
@@ -1,5 +1,15 @@
# List of programs to build
+ifndef CROSS_COMPILE
hostprogs-y := testptp
+else
+# MIPS system calls are defined based on the -mabi that is passed
+# to the toolchain which may or may not be a valid option
+# for the host toolchain. So disable testptp if target architecture
+# is MIPS but the host isn't.
+ifndef CONFIG_MIPS
+hostprogs-y := testptp
+endif
+endif

# Tell kbuild to always build the programs
always := $(hostprogs-y)
--
2.1.2


2014-10-21 11:07:49

by Richard Cochran

[permalink] [raw]
Subject: Re: [PATCH] Documentation: ptp: Fix build failure on MIPS cross builds

On Mon, Oct 20, 2014 at 09:42:18AM +0100, Markos Chandras wrote:
> diff --git a/Documentation/ptp/Makefile b/Documentation/ptp/Makefile
> index 293d6c09a11f..397c1cd2eda7 100644
> --- a/Documentation/ptp/Makefile
> +++ b/Documentation/ptp/Makefile
> @@ -1,5 +1,15 @@
> # List of programs to build
> +ifndef CROSS_COMPILE
> hostprogs-y := testptp
> +else
> +# MIPS system calls are defined based on the -mabi that is passed
> +# to the toolchain which may or may not be a valid option
> +# for the host toolchain. So disable testptp if target architecture
> +# is MIPS but the host isn't.
> +ifndef CONFIG_MIPS
> +hostprogs-y := testptp
> +endif
> +endif

It seems like a shame to simply give up and not compile this at all.
Is there no way to correctly cross compile this for MIPS?

Thanks,
Richard

2014-10-21 12:11:31

by Markos Chandras

[permalink] [raw]
Subject: Re: [PATCH] Documentation: ptp: Fix build failure on MIPS cross builds

On 10/21/2014 12:07 PM, Richard Cochran wrote:
> On Mon, Oct 20, 2014 at 09:42:18AM +0100, Markos Chandras wrote:
>> diff --git a/Documentation/ptp/Makefile b/Documentation/ptp/Makefile
>> index 293d6c09a11f..397c1cd2eda7 100644
>> --- a/Documentation/ptp/Makefile
>> +++ b/Documentation/ptp/Makefile
>> @@ -1,5 +1,15 @@
>> # List of programs to build
>> +ifndef CROSS_COMPILE
>> hostprogs-y := testptp
>> +else
>> +# MIPS system calls are defined based on the -mabi that is passed
>> +# to the toolchain which may or may not be a valid option
>> +# for the host toolchain. So disable testptp if target architecture
>> +# is MIPS but the host isn't.
>> +ifndef CONFIG_MIPS
>> +hostprogs-y := testptp
>> +endif
>> +endif
>
> It seems like a shame to simply give up and not compile this at all.
> Is there no way to correctly cross compile this for MIPS?
>
> Thanks,
> Richard
>

As far as I can see you don't cross-compile the file. You use the host
toolchain. There is no clean way to build it for host if you have your
kernel configured for MIPS. Perhaps maybe you could define
__MIPS_SIM_{ABI64, ABI32, NABI32} in the gcc command line (-D...) but
this is a bit ugly. Or maybe use the host headers instead of the ones in
the kernel source.

--
markos

2014-10-21 12:52:50

by Richard Cochran

[permalink] [raw]
Subject: Re: [PATCH] Documentation: ptp: Fix build failure on MIPS cross builds

(adding Peter Foley to CC ...)

On Tue, Oct 21, 2014 at 01:11:22PM +0100, Markos Chandras wrote:
> On 10/21/2014 12:07 PM, Richard Cochran wrote:
> > On Mon, Oct 20, 2014 at 09:42:18AM +0100, Markos Chandras wrote:
> >> diff --git a/Documentation/ptp/Makefile b/Documentation/ptp/Makefile
> >> index 293d6c09a11f..397c1cd2eda7 100644
> >> --- a/Documentation/ptp/Makefile
> >> +++ b/Documentation/ptp/Makefile
> >> @@ -1,5 +1,15 @@
> >> # List of programs to build
> >> +ifndef CROSS_COMPILE
> >> hostprogs-y := testptp
> >> +else
> >> +# MIPS system calls are defined based on the -mabi that is passed
> >> +# to the toolchain which may or may not be a valid option
> >> +# for the host toolchain. So disable testptp if target architecture
> >> +# is MIPS but the host isn't.
> >> +ifndef CONFIG_MIPS
> >> +hostprogs-y := testptp
> >> +endif
> >> +endif
> >
> > It seems like a shame to simply give up and not compile this at all.
> > Is there no way to correctly cross compile this for MIPS?
> >
> > Thanks,
> > Richard
> >
>
> As far as I can see you don't cross-compile the file. You use the host
> toolchain.

Look at Documentation/ptp/testptp.mk. There I do use $CROSS_COMPILE.

> There is no clean way to build it for host if you have your
> kernel configured for MIPS. Perhaps maybe you could define
> __MIPS_SIM_{ABI64, ABI32, NABI32} in the gcc command line (-D...) but
> this is a bit ugly. Or maybe use the host headers instead of the ones in
> the kernel source.

Your patch is for the file, Documentation/ptp/Makefile. I did not
write that file. Maybe Peter knows how to fix it?

Thanks,
Richard

2014-10-21 13:03:51

by Markos Chandras

[permalink] [raw]
Subject: Re: [PATCH] Documentation: ptp: Fix build failure on MIPS cross builds

On 10/21/2014 01:52 PM, Richard Cochran wrote:
> (adding Peter Foley to CC ...)
>
> On Tue, Oct 21, 2014 at 01:11:22PM +0100, Markos Chandras wrote:
>> On 10/21/2014 12:07 PM, Richard Cochran wrote:
>>> On Mon, Oct 20, 2014 at 09:42:18AM +0100, Markos Chandras wrote:
>>>> diff --git a/Documentation/ptp/Makefile b/Documentation/ptp/Makefile
>>>> index 293d6c09a11f..397c1cd2eda7 100644
>>>> --- a/Documentation/ptp/Makefile
>>>> +++ b/Documentation/ptp/Makefile
>>>> @@ -1,5 +1,15 @@
>>>> # List of programs to build
>>>> +ifndef CROSS_COMPILE
>>>> hostprogs-y := testptp
>>>> +else
>>>> +# MIPS system calls are defined based on the -mabi that is passed
>>>> +# to the toolchain which may or may not be a valid option
>>>> +# for the host toolchain. So disable testptp if target architecture
>>>> +# is MIPS but the host isn't.
>>>> +ifndef CONFIG_MIPS
>>>> +hostprogs-y := testptp
>>>> +endif
>>>> +endif
>>>
>>> It seems like a shame to simply give up and not compile this at all.
>>> Is there no way to correctly cross compile this for MIPS?
>>>
>>> Thanks,
>>> Richard
>>>
>>
>> As far as I can see you don't cross-compile the file. You use the host
>> toolchain.
>
> Look at Documentation/ptp/testptp.mk. There I do use $CROSS_COMPILE.

Hmm I can't see this testptp.mk file in the mainline. What tree are you
referring to?

markos linux (master) $ grep -r CROSS_COMPILE Documentation/ptp/*
markos linux (master) $

--
markos

2014-10-21 13:40:10

by Richard Cochran

[permalink] [raw]
Subject: Re: [PATCH] Documentation: ptp: Fix build failure on MIPS cross builds

On Tue, Oct 21, 2014 at 02:03:45PM +0100, Markos Chandras wrote:
>
> Hmm I can't see this testptp.mk file in the mainline. What tree are you
> referring to?

Sorry, I have net-next open in front of me. The same guy who added
the buggy Makefile deleted my working makefile...

Thanks,
Richard

2014-10-21 16:35:52

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] Documentation: ptp: Fix build failure on MIPS cross builds

From: Richard Cochran <[email protected]>
Date: Tue, 21 Oct 2014 13:07:25 +0200

> On Mon, Oct 20, 2014 at 09:42:18AM +0100, Markos Chandras wrote:
>> diff --git a/Documentation/ptp/Makefile b/Documentation/ptp/Makefile
>> index 293d6c09a11f..397c1cd2eda7 100644
>> --- a/Documentation/ptp/Makefile
>> +++ b/Documentation/ptp/Makefile
>> @@ -1,5 +1,15 @@
>> # List of programs to build
>> +ifndef CROSS_COMPILE
>> hostprogs-y := testptp
>> +else
>> +# MIPS system calls are defined based on the -mabi that is passed
>> +# to the toolchain which may or may not be a valid option
>> +# for the host toolchain. So disable testptp if target architecture
>> +# is MIPS but the host isn't.
>> +ifndef CONFIG_MIPS
>> +hostprogs-y := testptp
>> +endif
>> +endif
>
> It seems like a shame to simply give up and not compile this at all.
> Is there no way to correctly cross compile this for MIPS?

Yeah seriously, we should try to make this work instead of throwing our
hands in the air.

2014-10-21 16:58:56

by David Daney

[permalink] [raw]
Subject: Re: [PATCH] Documentation: ptp: Fix build failure on MIPS cross builds

On 10/21/2014 09:35 AM, David Miller wrote:
> From: Richard Cochran <[email protected]>
> Date: Tue, 21 Oct 2014 13:07:25 +0200
>
>> On Mon, Oct 20, 2014 at 09:42:18AM +0100, Markos Chandras wrote:
>>> diff --git a/Documentation/ptp/Makefile b/Documentation/ptp/Makefile
>>> index 293d6c09a11f..397c1cd2eda7 100644
>>> --- a/Documentation/ptp/Makefile
>>> +++ b/Documentation/ptp/Makefile
>>> @@ -1,5 +1,15 @@
>>> # List of programs to build
>>> +ifndef CROSS_COMPILE
>>> hostprogs-y := testptp
>>> +else
>>> +# MIPS system calls are defined based on the -mabi that is passed
>>> +# to the toolchain which may or may not be a valid option
>>> +# for the host toolchain. So disable testptp if target architecture
>>> +# is MIPS but the host isn't.
>>> +ifndef CONFIG_MIPS
>>> +hostprogs-y := testptp
>>> +endif
>>> +endif
>>
>> It seems like a shame to simply give up and not compile this at all.
>> Is there no way to correctly cross compile this for MIPS?
>
> Yeah seriously, we should try to make this work instead of throwing our
> hands in the air.
>

We cross compile things successfully all the time for all the various
MIPS ABIs.

It is a simple matter of having the Makefile setup for cross compiling.

What I don't understand is why we are using hostprogs in this Makefile.
Isn't this a program that would run on the target, not the build host?

David Daney

2014-10-21 18:28:08

by Richard Cochran

[permalink] [raw]
Subject: Re: [PATCH] Documentation: ptp: Fix build failure on MIPS cross builds

(adding Makefile author Peter Foley onto CC)

On Tue, Oct 21, 2014 at 09:58:51AM -0700, David Daney wrote:
> On 10/21/2014 09:35 AM, David Miller wrote:
> >From: Richard Cochran <[email protected]>
> >Date: Tue, 21 Oct 2014 13:07:25 +0200
> >
> >>On Mon, Oct 20, 2014 at 09:42:18AM +0100, Markos Chandras wrote:
> >>>diff --git a/Documentation/ptp/Makefile b/Documentation/ptp/Makefile
> >>>index 293d6c09a11f..397c1cd2eda7 100644
> >>>--- a/Documentation/ptp/Makefile
> >>>+++ b/Documentation/ptp/Makefile
> >>>@@ -1,5 +1,15 @@
> >>> # List of programs to build
> >>>+ifndef CROSS_COMPILE
> >>> hostprogs-y := testptp
> >>>+else
> >>>+# MIPS system calls are defined based on the -mabi that is passed
> >>>+# to the toolchain which may or may not be a valid option
> >>>+# for the host toolchain. So disable testptp if target architecture
> >>>+# is MIPS but the host isn't.
> >>>+ifndef CONFIG_MIPS
> >>>+hostprogs-y := testptp
> >>>+endif
> >>>+endif
> >>
> >>It seems like a shame to simply give up and not compile this at all.
> >>Is there no way to correctly cross compile this for MIPS?
> >
> >Yeah seriously, we should try to make this work instead of throwing our
> >hands in the air.
> >
>
> We cross compile things successfully all the time for all the
> various MIPS ABIs.
>
> It is a simple matter of having the Makefile setup for cross compiling.
>
> What I don't understand is why we are using hostprogs in this
> Makefile. Isn't this a program that would run on the target, not
> the build host?

Yes.

Peter, could you please fix it?

Thanks,
Richard

2014-10-21 22:05:15

by Peter Foley

[permalink] [raw]
Subject: Re: [PATCH] Documentation: ptp: Fix build failure on MIPS cross builds

On Tue, Oct 21, 2014 at 2:27 PM, Richard Cochran
<[email protected]> wrote:
> On Tue, Oct 21, 2014 at 09:58:51AM -0700, David Daney wrote:
>> What I don't understand is why we are using hostprogs in this
>> Makefile. Isn't this a program that would run on the target, not
>> the build host?
>
> Yes.
>
> Peter, could you please fix it?


The intention of these changes was to generate more compiliation
coverage for code in Documentation/
The underlying issue is that this doesn't work for cross-compiling
because kbuild doesn't have cross-compile support for userspace code.
I submitted a patch to disable building Documentation when
cross-compiling, as the consensus in the thread that resulted in that
patch (https://lkml.org/lkml/2014/10/8/510) was that implementing
targetprogs in kbuild was not currently worth it.
I can try to take a crack at adding targetprogs support, but I'm
rather busy right now, so it may take a little while.

Thanks,

Peter

2014-10-22 08:03:35

by Richard Cochran

[permalink] [raw]
Subject: Re: [PATCH] Documentation: ptp: Fix build failure on MIPS cross builds

On Tue, Oct 21, 2014 at 06:04:51PM -0400, Peter Foley wrote:
> The intention of these changes was to generate more compiliation
> coverage for code in Documentation/

Sounds good.

> The underlying issue is that this doesn't work for cross-compiling
> because kbuild doesn't have cross-compile support for userspace code.

Well, my testptp does cross compile just fine. All it needs is the glibc
library bundled with the tool chain and the kernel headers.

> I submitted a patch to disable building Documentation when
> cross-compiling, as the consensus in the thread that resulted in that
> patch (https://lkml.org/lkml/2014/10/8/510) was that implementing
> targetprogs in kbuild was not currently worth it.

So this patch did not make it in, right?

Otherwise people wouldn't be disabling cross compilation ad hoc, like
in the patch that started this thread.

> I can try to take a crack at adding targetprogs support, but I'm
> rather busy right now, so it may take a little while.

No rush, please do.

In the mean time, I would like to restore the testptp.mk that *does*
cross compile, so that people may use the test program if they
want. In fact I use this all the time, and so I am a bit annoyed that
something working was deleted and replaced with something broken.

Thanks,
Richard

2014-10-22 14:10:03

by Peter Foley

[permalink] [raw]
Subject: Re: [PATCH] Documentation: ptp: Fix build failure on MIPS cross builds

On Wed, Oct 22, 2014 at 4:03 AM, Richard Cochran
<[email protected]> wrote:
> In the mean time, I would like to restore the testptp.mk that *does*
> cross compile, so that people may use the test program if they
> want. In fact I use this all the time, and so I am a bit annoyed that
> something working was deleted and replaced with something broken.

Sure, I didn't realize that anyone was actually using testptp.mk on a
regular basis.
Feel free to restore it.