diff mbox series

回复:[PATCH v1] include/mk/env_post.mk: enable __ANDROID__ definition for Android build

Message ID db7687f3-40ca-495e-aa76-efcce204cda7.ruanzw@xiaopeng.com
State Superseded
Delegated to: Petr Vorel
Headers show
Series 回复:[PATCH v1] include/mk/env_post.mk: enable __ANDROID__ definition for Android build | expand

Commit Message

阮正旺 April 9, 2019, 4:45 p.m. UTC
Could anyone help me to review this patch? This is useful to cross-compile ltp for Android without specifying '-D__ANDROID__' in configure step.

Thanks!
Zhengwang


------------------------------------------------------------------
发件人:Zhengwang Ruan <ruanzw@xiaopeng.com>
发送时间:2019年4月9日(星期二) 12:05
收件人:ltp <ltp@lists.linux.it>
抄 送:Zhengwang Ruan <ruanzw@xiaopeng.com>
主 题:[PATCH v1] include/mk/env_post.mk: enable __ANDROID__ definition for Android build

Enable the __ANDROID__ definition by default for Android build, otherwise we
should manually enable it by configure command.

Signed-off-by: Zhengwang Ruan <ruanzw@xiaopeng.com>
---
 include/mk/env_post.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Petr Vorel April 10, 2019, 2:16 p.m. UTC | #1
Hi Sandeep, Steve,

> Could anyone help me to review this patch? This is useful to cross-compile ltp for Android without specifying '-D__ANDROID__' in configure step.

> Thanks!
> Zhengwang


> ------------------------------------------------------------------
> 发件人:Zhengwang Ruan <ruanzw@xiaopeng.com>
> 发送时间:2019年4月9日(星期二) 12:05
> 收件人:ltp <ltp@lists.linux.it>
> 抄 送:Zhengwang Ruan <ruanzw@xiaopeng.com>
> 主 题:[PATCH v1] include/mk/env_post.mk: enable __ANDROID__ definition for Android build

> Enable the __ANDROID__ definition by default for Android build, otherwise we
> should manually enable it by configure command.

> Signed-off-by: Zhengwang Ruan <ruanzw@xiaopeng.com>
> ---
>  include/mk/env_post.mk | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

> diff --git a/include/mk/env_post.mk b/include/mk/env_post.mk
> index 913bdf5..7953e0a 100644
> --- a/include/mk/env_post.mk
> +++ b/include/mk/env_post.mk
> @@ -44,7 +44,7 @@ endif
>  ifeq ($(ANDROID),1)
>  # There are many undeclared functions, it's best not to accidentally overlook
>  # them.
> -CFLAGS    += -Werror-implicit-function-declaration
> +CFLAGS    += -Werror-implicit-function-declaration -D__ANDROID__
Would adding __ANDROID__ definition help building LTP with distro
cross-compiler? (i.e. no NDK, no inside AOSP tree)?
I guess so and therefore, I'd be for this change.
I see some projects added it as well (busybox [1] [2], dnsmasq [3]).
BTW: where is defined for AOSP and NDK?

BTW (@cyril): I guess -Werror-implicit-function-declaration is the code which
requires adding <string.h> and <strings.h> (see my fix 4053a2551 ("lib: Add
missing <string.h> and <strings.h> includes")), I'd be for either adding it to
for all or removing it.

>  LDFLAGS    += -L$(top_builddir)/lib/android_libpthread
>  LDFLAGS    += -L$(top_builddir)/lib/android_librt

Kind regards,
Petr

[1] https://git.busybox.net/busybox/tree/configs/android_defconfig
[2] https://git.busybox.net/busybox/tree/configs/android_ndk_defconfig
[3] http://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=blob_plain;f=bld/Android.mk;hb=HEAD
阮正旺 April 11, 2019, 3:38 a.m. UTC | #2
Hi Petr,


-------- Original Message --------
From: Petr Vorel
Sent: Wed, 10 Apr 2019 16:16:15 +0200
To: Sandeep Patil, Steve Muckle
Cc: Ltp, Zhengwang Ruan, Cyril Hrubis
Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable 
__ANDROID__ definition for Android build
> Hi Sandeep, Steve,
>
>> Could anyone help me to review this patch? This is useful to cross-compile ltp for Android without specifying '-D__ANDROID__' in configure step.
>> Thanks!
>> Zhengwang
>
>> ------------------------------------------------------------------
>> 发件人:Zhengwang Ruan <ruanzw@xiaopeng.com>
>> 发送时间:2019年4月9日(星期二) 12:05
>> 收件人:ltp <ltp@lists.linux.it>
>> 抄 送:Zhengwang Ruan <ruanzw@xiaopeng.com>
>> 主 题:[PATCH v1] include/mk/env_post.mk: enable __ANDROID__ definition for Android build
>> Enable the __ANDROID__ definition by default for Android build, otherwise we
>> should manually enable it by configure command.
>> Signed-off-by: Zhengwang Ruan <ruanzw@xiaopeng.com>
>> ---
>>   include/mk/env_post.mk | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>> diff --git a/include/mk/env_post.mk b/include/mk/env_post.mk
>> index 913bdf5..7953e0a 100644
>> --- a/include/mk/env_post.mk
>> +++ b/include/mk/env_post.mk
>> @@ -44,7 +44,7 @@ endif
>>   ifeq ($(ANDROID),1)
>>   # There are many undeclared functions, it's best not to accidentally overlook
>>   # them.
>> -CFLAGS    += -Werror-implicit-function-declaration
>> +CFLAGS    += -Werror-implicit-function-declaration -D__ANDROID__
> Would adding __ANDROID__ definition help building LTP with distro
> cross-compiler? (i.e. no NDK, no inside AOSP tree)?
> I guess so and therefore, I'd be for this change.
> I see some projects added it as well (busybox [1] [2], dnsmasq [3]).
> BTW: where is defined for AOSP and NDK?


I found that '-DANDROID' instead of '-D__ANDROID__' was passed while 
cross-compiling binaries in my AOSP project.


Thanks!

Zhengwang

>
> BTW (@cyril): I guess -Werror-implicit-function-declaration is the code which
> requires adding <string.h> and <strings.h> (see my fix 4053a2551 ("lib: Add
> missing <string.h> and <strings.h> includes")), I'd be for either adding it to
> for all or removing it.
>
>>   LDFLAGS    += -L$(top_builddir)/lib/android_libpthread
>>   LDFLAGS    += -L$(top_builddir)/lib/android_librt
> Kind regards,
> Petr
>
> [1] https://git.busybox.net/busybox/tree/configs/android_defconfig
> [2] https://git.busybox.net/busybox/tree/configs/android_ndk_defconfig
> [3] http://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=blob_plain;f=bld/Android.mk;hb=HEAD
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body smarttemplateinserted="true">
    <div id="smartTemplate4-template">
      <p>Hi Petr, <br>
      </p>
    </div>
    <br>
    <div id="smartTemplate4-quoteHeader">-------- Original Message --------<br>
      From: Petr Vorel<br>
      Sent: Wed, 10 Apr 2019 16:16:15 +0200<br>
      To: Sandeep Patil, Steve Muckle<br>
      Cc: Ltp, Zhengwang Ruan, Cyril Hrubis<br>
      Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable
      __ANDROID__ definition for Android build<br>
    </div>
    <blockquote type="cite" cite="mid:20190410141615.GA10303@x230">
      <pre class="moz-quote-pre" wrap="">Hi Sandeep, Steve,

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Could anyone help me to review this patch? This is useful to cross-compile ltp for Android without specifying '-D__ANDROID__' in configure step.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Thanks!
Zhengwang
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">------------------------------------------------------------------
发件人:Zhengwang Ruan <a class="moz-txt-link-rfc2396E" href="mailto:ruanzw@xiaopeng.com">&lt;ruanzw@xiaopeng.com&gt;</a>
发送时间:2019年4月9日(星期二) 12:05
收件人:ltp <a class="moz-txt-link-rfc2396E" href="mailto:ltp@lists.linux.it">&lt;ltp@lists.linux.it&gt;</a>
抄 送:Zhengwang Ruan <a class="moz-txt-link-rfc2396E" href="mailto:ruanzw@xiaopeng.com">&lt;ruanzw@xiaopeng.com&gt;</a>
主 题:[PATCH v1] include/mk/env_post.mk: enable __ANDROID__ definition for Android build
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Enable the __ANDROID__ definition by default for Android build, otherwise we
should manually enable it by configure command.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Signed-off-by: Zhengwang Ruan <a class="moz-txt-link-rfc2396E" href="mailto:ruanzw@xiaopeng.com">&lt;ruanzw@xiaopeng.com&gt;</a>
---
 include/mk/env_post.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">diff --git a/include/mk/env_post.mk b/include/mk/env_post.mk
index 913bdf5..7953e0a 100644
--- a/include/mk/env_post.mk
+++ b/include/mk/env_post.mk
@@ -44,7 +44,7 @@ endif
 ifeq ($(ANDROID),1)
 # There are many undeclared functions, it's best not to accidentally overlook
 # them.
-CFLAGS    += -Werror-implicit-function-declaration
+CFLAGS    += -Werror-implicit-function-declaration -D__ANDROID__
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">Would adding __ANDROID__ definition help building LTP with distro
cross-compiler? (i.e. no NDK, no inside AOSP tree)?
I guess so and therefore, I'd be for this change.
I see some projects added it as well (busybox [1] [2], dnsmasq [3]).
BTW: where is defined for AOSP and NDK?</pre>
    </blockquote>
    <p><br>
    </p>
    <p>I found that '-DANDROID' instead of '-D__ANDROID__' was passed
      while cross-compiling binaries in my AOSP project.</p>
    <p><br>
    </p>
    <p>Thanks!</p>
    <p>Zhengwang<br>
    </p>
    <blockquote type="cite" cite="mid:20190410141615.GA10303@x230">
      <pre class="moz-quote-pre" wrap="">

BTW (@cyril): I guess -Werror-implicit-function-declaration is the code which
requires adding &lt;string.h&gt; and &lt;strings.h&gt; (see my fix 4053a2551 ("lib: Add
missing &lt;string.h&gt; and &lt;strings.h&gt; includes")), I'd be for either adding it to
for all or removing it.

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap=""> LDFLAGS    += -L$(top_builddir)/lib/android_libpthread
 LDFLAGS    += -L$(top_builddir)/lib/android_librt
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
Kind regards,
Petr

[1] <a class="moz-txt-link-freetext" href="https://git.busybox.net/busybox/tree/configs/android_defconfig">https://git.busybox.net/busybox/tree/configs/android_defconfig</a>
[2] <a class="moz-txt-link-freetext" href="https://git.busybox.net/busybox/tree/configs/android_ndk_defconfig">https://git.busybox.net/busybox/tree/configs/android_ndk_defconfig</a>
[3] <a class="moz-txt-link-freetext" href="http://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=blob_plain;f=bld/Android.mk;hb=HEAD">http://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=blob_plain;f=bld/Android.mk;hb=HEAD</a>
</pre>
    </blockquote>
  </body>
</html>
Sandeep Patil April 11, 2019, 4:27 p.m. UTC | #3
On Wed, Apr 10, 2019 at 04:16:15PM +0200, Petr Vorel wrote:
> Hi Sandeep, Steve,
> 
> > Could anyone help me to review this patch? This is useful to cross-compile ltp for Android without specifying '-D__ANDROID__' in configure step.
> 
> > Thanks!
> > Zhengwang
> 
> 
> > ------------------------------------------------------------------
> > 发件人:Zhengwang Ruan <ruanzw@xiaopeng.com>
> > 发送时间:2019年4月9日(星期二) 12:05
> > 收件人:ltp <ltp@lists.linux.it>
> > 抄 送:Zhengwang Ruan <ruanzw@xiaopeng.com>
> > 主 题:[PATCH v1] include/mk/env_post.mk: enable __ANDROID__ definition for Android build
> 
> > Enable the __ANDROID__ definition by default for Android build, otherwise we
> > should manually enable it by configure command.
> 
> > Signed-off-by: Zhengwang Ruan <ruanzw@xiaopeng.com>
> > ---
> >  include/mk/env_post.mk | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> > diff --git a/include/mk/env_post.mk b/include/mk/env_post.mk
> > index 913bdf5..7953e0a 100644
> > --- a/include/mk/env_post.mk
> > +++ b/include/mk/env_post.mk
> > @@ -44,7 +44,7 @@ endif
> >  ifeq ($(ANDROID),1)
> >  # There are many undeclared functions, it's best not to accidentally overlook
> >  # them.
> > -CFLAGS    += -Werror-implicit-function-declaration
> > +CFLAGS    += -Werror-implicit-function-declaration -D__ANDROID__
> Would adding __ANDROID__ definition help building LTP with distro
> cross-compiler? (i.e. no NDK, no inside AOSP tree)?
> I guess so and therefore, I'd be for this change.
> I see some projects added it as well (busybox [1] [2], dnsmasq [3]).
> BTW: where is defined for AOSP and NDK?

I think I've used __ANDROID__ and __BIONIC__ in the past for android-specific
things.  Honestly, I haven't tried to build for Android outside of AOSP tree
yet. I am happy to test this if you tell me how? (sorry for that.)

Steve will also be back by 4/15 and he would know this more than I do.
So,  Ideally, if we can wait for him it will be great. In the mean time, I
can test..

FWIW, I want to be able to do this as well. I know its a lot of pain to have
to checkout 100s of gigabytes of AOSP tree in order to build LTP for Android
right now. So, let me know how I can test and compare.

<snip>


- ssp
Petr Vorel April 11, 2019, 5:37 p.m. UTC | #4
Hi Sandeep,

thanks a lot for your comments.
...
> > > +++ b/include/mk/env_post.mk
> > > @@ -44,7 +44,7 @@ endif
> > >  ifeq ($(ANDROID),1)
> > >  # There are many undeclared functions, it's best not to accidentally overlook
> > >  # them.
> > > -CFLAGS    += -Werror-implicit-function-declaration
> > > +CFLAGS    += -Werror-implicit-function-declaration -D__ANDROID__
> > Would adding __ANDROID__ definition help building LTP with distro
> > cross-compiler? (i.e. no NDK, no inside AOSP tree)?
> > I guess so and therefore, I'd be for this change.
> > I see some projects added it as well (busybox [1] [2], dnsmasq [3]).
> > BTW: where is defined for AOSP and NDK?

> I think I've used __ANDROID__ and __BIONIC__ in the past for android-specific
> things.  Honestly, I haven't tried to build for Android outside of AOSP tree
> yet. I am happy to test this if you tell me how? (sorry for that.)
Great, thanks a lot!

According to [1] android toolchain (I guess both AOSP and NDK toolchain) define
__ANDROID__. Which is what I'd expect.

Grepping aosp only dnsmasq and swiftshader use -D__ANDROID__ (these are from
externals). -DANDROID is use more times (e.g. some drivers in hardware - ril,
qcom, libsensors and wpa_supplicant).

From my point of view, instead of -D__ANDROID__ or -DANDROID I'd prefer to to have
proper #ifdef HAVE_FOO guarders made by autotools checks. As android is not the
only minor libc. But I understand it's not always possible and we already use
some #ifdef __ANDROID__ in library sources and headers, so ack from myself to
help compilation outside AOSP and without NDK.

Acked-by: Petr Vorel <pvorel@suse.cz>

> Steve will also be back by 4/15 and he would know this more than I do.
> So,  Ideally, if we can wait for him it will be great. In the mean time, I
> can test..
Sure, this can wait for him.

> FWIW, I want to be able to do this as well. I know its a lot of pain to have
> to checkout 100s of gigabytes of AOSP tree in order to build LTP for Android
> right now. So, let me know how I can test and compare.
Simple 'make ANDROID=1' will do the build ANDROID is for skipping some tests
which are not android ready (+ this patch). I guess without this you probably
also want to remove -Werror-implicit-function-declaration (I haven't pushed all
my fixes of missing <string.h> and <strings.h> as this is infinite work so far.

I have in my private todo list to write some doc about building LTP for Android.
But probably you, Android devs, are more appropriate people :).

> - ssp

Kind regards,
Petr

[1] https://groups.google.com/forum/#!topic/android-ndk/cf9_f1SLXls
Petr Vorel April 11, 2019, 11:40 p.m. UTC | #5
Hi Sandeep,

> > > > -CFLAGS    += -Werror-implicit-function-declaration
> > > > +CFLAGS    += -Werror-implicit-function-declaration -D__ANDROID__
> > > Would adding __ANDROID__ definition help building LTP with distro
> > > cross-compiler? (i.e. no NDK, no inside AOSP tree)?
> > > I guess so and therefore, I'd be for this change.
> > > I see some projects added it as well (busybox [1] [2], dnsmasq [3]).
> > > BTW: where is defined for AOSP and NDK?

> > I think I've used __ANDROID__ and __BIONIC__ in the past for android-specific
> > things.  Honestly, I haven't tried to build for Android outside of AOSP tree
> > yet. I am happy to test this if you tell me how? (sorry for that.)
> Great, thanks a lot!

> According to [1] android toolchain (I guess both AOSP and NDK toolchain) define
> __ANDROID__. Which is what I'd expect.

> Grepping aosp only dnsmasq and swiftshader use -D__ANDROID__ (these are from
> externals). -DANDROID is use more times (e.g. some drivers in hardware - ril,
> qcom, libsensors and wpa_supplicant).

> From my point of view, instead of -D__ANDROID__ or -DANDROID I'd prefer to to have
> proper #ifdef HAVE_FOO guarders made by autotools checks. As android is not the
> only minor libc. But I understand it's not always possible and we already use
> some #ifdef __ANDROID__ in library sources and headers, so ack from myself to
> help compilation outside AOSP and without NDK.
Actually I was wrong. 1) I was using NDK toolchain. I'd expect it'd generate
__ANDROID__, but I don't see it in the output. 2) Building for android with
distro toolchain doesn't make sense as it wouldn't have Bionic.

Kind regards,
Petr
阮正旺 April 12, 2019, 3:09 a.m. UTC | #6
-------- Original Message --------
From: Sandeep Patil
Sent: Thu, 11 Apr 2019 09:27:24 -0700
To: Petr Vorel
Cc: Ltp
Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk: enable 
__ANDROID__ definition for Android b uild
> On Wed, Apr 10, 2019 at 04:16:15PM +0200, Petr Vorel wrote:
>> Hi Sandeep, Steve,
>>
>>> Could anyone help me to review this patch? This is useful to cross-compile ltp for Android without specifying '-D__ANDROID__' in configure step.
>>> Thanks!
>>> Zhengwang
>>
>>> ------------------------------------------------------------------
>>> 发件人:Zhengwang Ruan <ruanzw@xiaopeng.com>
>>> 发送时间:2019年4月9日(星期二) 12:05
>>> 收件人:ltp <ltp@lists.linux.it>
>>> 抄 送:Zhengwang Ruan <ruanzw@xiaopeng.com>
>>> 主 题:[PATCH v1] include/mk/env_post.mk: enable __ANDROID__ definition for Android build
>>> Enable the __ANDROID__ definition by default for Android build, otherwise we
>>> should manually enable it by configure command.
>>> Signed-off-by: Zhengwang Ruan <ruanzw@xiaopeng.com>
>>> ---
>>>   include/mk/env_post.mk | 2 +-
>>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>> diff --git a/include/mk/env_post.mk b/include/mk/env_post.mk
>>> index 913bdf5..7953e0a 100644
>>> --- a/include/mk/env_post.mk
>>> +++ b/include/mk/env_post.mk
>>> @@ -44,7 +44,7 @@ endif
>>>   ifeq ($(ANDROID),1)
>>>   # There are many undeclared functions, it's best not to accidentally overlook
>>>   # them.
>>> -CFLAGS    += -Werror-implicit-function-declaration
>>> +CFLAGS    += -Werror-implicit-function-declaration -D__ANDROID__
>> Would adding __ANDROID__ definition help building LTP with distro
>> cross-compiler? (i.e. no NDK, no inside AOSP tree)?
>> I guess so and therefore, I'd be for this change.
>> I see some projects added it as well (busybox [1] [2], dnsmasq [3]).
>> BTW: where is defined for AOSP and NDK?
> I think I've used __ANDROID__ and __BIONIC__ in the past for android-specific
> things.  Honestly, I haven't tried to build for Android outside of AOSP tree
> yet. I am happy to test this if you tell me how? (sorry for that.)

Hi Sandeep,


You can try the steps below to make a build outside AOSP. In my case, it 
works fine.

$ autoreconf --install

$ ./configure --prefix=/tmp/ltp 
CC=${BUILD_PROJ_DIR}/prebuilts/clang/host/linux-x86/clang-4691093/bin/clang 
AR=${BUILD_PROJ_DIR}/prebuilts/clang/host/linux-x86/clang-4691093/bin/llvm-ar 
CFLAGS="-I ${BUILD_PROJ_DIR}/libnativehelper/include_jni -I 
${BUILD_PROJ_DIR}/system/core/include -I 
${BUILD_PROJ_DIR}/system/media/audio/include -I 
${BUILD_PROJ_DIR}/hardware/libhardware/include -I 
${BUILD_PROJ_DIR}/hardware/libhardware_legacy/include -I 
${BUILD_PROJ_DIR}/hardware/ril/include -I 
${BUILD_PROJ_DIR}/libnativehelper/include -I 
${BUILD_PROJ_DIR}/frameworks/native/include -I 
${BUILD_PROJ_DIR}/frameworks/native/opengl/include -I 
${BUILD_PROJ_DIR}/frameworks/av/include -isystem 
${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/include 
-isystem ${BUILD_PROJ_DIR}/bionic/libc/include -isystem 
${BUILD_PROJ_DIR}/bionic/libc/kernel/uapi -isystem 
${BUILD_PROJ_DIR}/bionic/libc/kernel/uapi/asm-arm64 -isystem 
${BUILD_PROJ_DIR}/bionic/libc/kernel/android/scsi -isystem 
${BUILD_PROJ_DIR}/bionic/libc/kernel/android/uapi -target 
aarch64-linux-android 
-B${BUILD_PROJ_DIR}/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin 
-pthread -nostdlib -D__ANDROID__" --host=aarch64-linux-gnu 
LDFLAGS="-nostdlib -Wl,-dynamic-linker,/system/bin/linker64 
-Wl,--gc-sections -Wl,-z,nocopyreloc 
-Wl,-rpath-link=${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/lib 
${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/lib/crtbegin_dynamic.o 
-Wl,--whole-archive  -Wl,--no-whole-archive 
${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/STATIC_LIBRARIES/libclang_rt.ubsan_minimal-aarch64-android_intermediates/libclang_rt.ubsan_minimal-aarch64-android.a 
${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/STATIC_LIBRARIES/libcompiler_rt-extras_intermediates/libcompiler_rt-extras.a 
${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/STATIC_LIBRARIES/libatomic_intermediates/libatomic.a 
${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/STATIC_LIBRARIES/libgcc_intermediates/libgcc.a 
-Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5 
-Wl,--warn-shared-textrel -Wl,--fatal-warnings 
-Wl,--no-undefined-version -Wl,-m,aarch64_elf64_le_vec 
-Wl,--hash-style=gnu -fuse-ld=gold -Wl,--icf=safe 
-Wl,--exclude-libs,libclang_rt.ubsan_minimal-aarch64-android.a 
-Wl,--no-undefined 
-B${BUILD_PROJ_DIR}/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin 
-L${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/lib -lc++ -lc 
-lm -ldl 
${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/lib/crtend_android.o"

$ make ANDROID=1


BTW,  ${BUILD_PROJ_DIR} refers to the path of your AOSP project, and 
${PRODUCT_NAME} refers to the product nickname inside your organization. 
you need to export these two variables before launch the above configure.


But unfortunately, you will encounter other build errors, especially 
those caused by -Werror-implicit-function-declaration. But I think it 
should be enough to tell the deference between __ANDROID__ and ANDROID.


Good luck! :-)

Zhengwang

>
> Steve will also be back by 4/15 and he would know this more than I do.
> So,  Ideally, if we can wait for him it will be great. In the mean time, I
> can test..
>
> FWIW, I want to be able to do this as well. I know its a lot of pain to have
> to checkout 100s of gigabytes of AOSP tree in order to build LTP for Android
> right now. So, let me know how I can test and compare.
>
> <snip>
>
>
> - ssp
>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body smarttemplateinserted="true">
    <br>
    <div id="smartTemplate4-quoteHeader">-------- Original Message --------<br>
      From: Sandeep Patil<br>
      Sent: Thu, 11 Apr 2019 09:27:24 -0700<br>
      To: Petr Vorel<br>
      Cc: Ltp<br>
      Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk: enable
      __ANDROID__ definition for Android b uild<br>
    </div>
    <blockquote type="cite"
      cite="mid:20190411162724.GC124555@google.com">
      <pre class="moz-quote-pre" wrap="">On Wed, Apr 10, 2019 at 04:16:15PM +0200, Petr Vorel wrote:
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Hi Sandeep, Steve,

</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">Could anyone help me to review this patch? This is useful to cross-compile ltp for Android without specifying '-D__ANDROID__' in configure step.
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">Thanks!
Zhengwang
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">

</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">------------------------------------------------------------------
发件人:Zhengwang Ruan <a class="moz-txt-link-rfc2396E" href="mailto:ruanzw@xiaopeng.com">&lt;ruanzw@xiaopeng.com&gt;</a>
发送时间:2019年4月9日(星期二) 12:05
收件人:ltp <a class="moz-txt-link-rfc2396E" href="mailto:ltp@lists.linux.it">&lt;ltp@lists.linux.it&gt;</a>
抄 送:Zhengwang Ruan <a class="moz-txt-link-rfc2396E" href="mailto:ruanzw@xiaopeng.com">&lt;ruanzw@xiaopeng.com&gt;</a>
主 题:[PATCH v1] include/mk/env_post.mk: enable __ANDROID__ definition for Android build
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">Enable the __ANDROID__ definition by default for Android build, otherwise we
should manually enable it by configure command.
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">Signed-off-by: Zhengwang Ruan <a class="moz-txt-link-rfc2396E" href="mailto:ruanzw@xiaopeng.com">&lt;ruanzw@xiaopeng.com&gt;</a>
---
 include/mk/env_post.mk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">diff --git a/include/mk/env_post.mk b/include/mk/env_post.mk
index 913bdf5..7953e0a 100644
--- a/include/mk/env_post.mk
+++ b/include/mk/env_post.mk
@@ -44,7 +44,7 @@ endif
 ifeq ($(ANDROID),1)
 # There are many undeclared functions, it's best not to accidentally overlook
 # them.
-CFLAGS    += -Werror-implicit-function-declaration
+CFLAGS    += -Werror-implicit-function-declaration -D__ANDROID__
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">Would adding __ANDROID__ definition help building LTP with distro
cross-compiler? (i.e. no NDK, no inside AOSP tree)?
I guess so and therefore, I'd be for this change.
I see some projects added it as well (busybox [1] [2], dnsmasq [3]).
BTW: where is defined for AOSP and NDK?
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
I think I've used __ANDROID__ and __BIONIC__ in the past for android-specific
things.  Honestly, I haven't tried to build for Android outside of AOSP tree
yet. I am happy to test this if you tell me how? (sorry for that.)</pre>
    </blockquote>
    <p>Hi Sandeep,</p>
    <p><br>
    </p>
    <p>You can try the steps below to make a build outside AOSP. In my
      case, it works fine.<br>
    </p>
    <p>$ autoreconf --install</p>
    <p>$ ./configure --prefix=/tmp/ltp
CC=${BUILD_PROJ_DIR}/prebuilts/clang/host/linux-x86/clang-4691093/bin/clang
AR=${BUILD_PROJ_DIR}/prebuilts/clang/host/linux-x86/clang-4691093/bin/llvm-ar
      CFLAGS="-I ${BUILD_PROJ_DIR}/libnativehelper/include_jni -I
      ${BUILD_PROJ_DIR}/system/core/include -I
      ${BUILD_PROJ_DIR}/system/media/audio/include -I
      ${BUILD_PROJ_DIR}/hardware/libhardware/include -I
      ${BUILD_PROJ_DIR}/hardware/libhardware_legacy/include -I
      ${BUILD_PROJ_DIR}/hardware/ril/include -I
      ${BUILD_PROJ_DIR}/libnativehelper/include -I
      ${BUILD_PROJ_DIR}/frameworks/native/include -I
      ${BUILD_PROJ_DIR}/frameworks/native/opengl/include -I
      ${BUILD_PROJ_DIR}/frameworks/av/include -isystem
      ${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/include
      -isystem ${BUILD_PROJ_DIR}/bionic/libc/include -isystem
      ${BUILD_PROJ_DIR}/bionic/libc/kernel/uapi -isystem
      ${BUILD_PROJ_DIR}/bionic/libc/kernel/uapi/asm-arm64 -isystem
      ${BUILD_PROJ_DIR}/bionic/libc/kernel/android/scsi -isystem
      ${BUILD_PROJ_DIR}/bionic/libc/kernel/android/uapi -target
      aarch64-linux-android
-B${BUILD_PROJ_DIR}/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin
      -pthread -nostdlib <font color="#cc0000">-D__ANDROID__</font>"
      --host=aarch64-linux-gnu LDFLAGS="-nostdlib
      -Wl,-dynamic-linker,/system/bin/linker64 -Wl,--gc-sections
      -Wl,-z,nocopyreloc
-Wl,-rpath-link=${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/lib
${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/lib/crtbegin_dynamic.o
      -Wl,--whole-archive  -Wl,--no-whole-archive  
${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/STATIC_LIBRARIES/libclang_rt.ubsan_minimal-aarch64-android_intermediates/libclang_rt.ubsan_minimal-aarch64-android.a 
${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/STATIC_LIBRARIES/libcompiler_rt-extras_intermediates/libcompiler_rt-extras.a  
${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/STATIC_LIBRARIES/libatomic_intermediates/libatomic.a
${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/STATIC_LIBRARIES/libgcc_intermediates/libgcc.a
      -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5
      -Wl,--warn-shared-textrel -Wl,--fatal-warnings
      -Wl,--no-undefined-version -Wl,-m,aarch64_elf64_le_vec
      -Wl,--hash-style=gnu -fuse-ld=gold -Wl,--icf=safe
      -Wl,--exclude-libs,libclang_rt.ubsan_minimal-aarch64-android.a
      -Wl,--no-undefined
-B${BUILD_PROJ_DIR}/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/aarch64-linux-android/bin
      -L${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/lib
      -lc++ -lc -lm -ldl
${BUILD_PROJ_DIR}/out/target/product/${PRODUCT_NAME}/obj/lib/crtend_android.o"</p>
    <p>$ make ANDROID=1<br>
    </p>
    <p><br>
    </p>
    <p>BTW,  ${BUILD_PROJ_DIR} refers to the path of your AOSP project,
      and ${PRODUCT_NAME} refers to the product nickname inside your
      organization. you need to export these two variables before launch
      the above configure.</p>
    <p><br>
    </p>
    <p>But unfortunately, you will encounter other build errors,
      especially those caused by -Werror-implicit-function-declaration.
      But I think it should be enough to tell the deference between <font
        color="#cc0000"><font color="#000000">__ANDROID__ and ANDROID.</font></font></p>
    <p><font color="#cc0000"><font color="#000000"><br>
        </font></font></p>
    <p><font color="#cc0000"><font color="#000000">Good luck! :-)</font></font></p>
    <p><font color="#cc0000"><font color="#000000">Zhengwang<br>
        </font></font></p>
    <blockquote type="cite"
      cite="mid:20190411162724.GC124555@google.com">
      <pre class="moz-quote-pre" wrap="">

Steve will also be back by 4/15 and he would know this more than I do.
So,  Ideally, if we can wait for him it will be great. In the mean time, I
can test..

FWIW, I want to be able to do this as well. I know its a lot of pain to have
to checkout 100s of gigabytes of AOSP tree in order to build LTP for Android
right now. So, let me know how I can test and compare.

&lt;snip&gt;


- ssp

</pre>
    </blockquote>
  </body>
</html>
阮正旺 April 12, 2019, 4:45 a.m. UTC | #7
Hi Petr,


-------- Original Message --------
From: Petr Vorel
Sent: Fri, 12 Apr 2019 01:40:42 +0200
To: Sandeep Patil
Cc: Ltp
Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk: enable 
__ANDROID__ definition for Android b uild
> Hi Sandeep,
>
>>>>> -CFLAGS    += -Werror-implicit-function-declaration
>>>>> +CFLAGS    += -Werror-implicit-function-declaration -D__ANDROID__
>>>> Would adding __ANDROID__ definition help building LTP with distro
>>>> cross-compiler? (i.e. no NDK, no inside AOSP tree)?
>>>> I guess so and therefore, I'd be for this change.
>>>> I see some projects added it as well (busybox [1] [2], dnsmasq [3]).
>>>> BTW: where is defined for AOSP and NDK?
>>> I think I've used __ANDROID__ and __BIONIC__ in the past for android-specific
>>> things.  Honestly, I haven't tried to build for Android outside of AOSP tree
>>> yet. I am happy to test this if you tell me how? (sorry for that.)
>> Great, thanks a lot!
>> According to [1] android toolchain (I guess both AOSP and NDK toolchain) define
>> __ANDROID__. Which is what I'd expect.
>> Grepping aosp only dnsmasq and swiftshader use -D__ANDROID__ (these are from
>> externals). -DANDROID is use more times (e.g. some drivers in hardware - ril,
>> qcom, libsensors and wpa_supplicant).
>>  From my point of view, instead of -D__ANDROID__ or -DANDROID I'd prefer to to have
>> proper #ifdef HAVE_FOO guarders made by autotools checks. As android is not the
>> only minor libc. But I understand it's not always possible and we already use
>> some #ifdef __ANDROID__ in library sources and headers, so ack from myself to
>> help compilation outside AOSP and without NDK.
> Actually I was wrong. 1) I was using NDK toolchain. I'd expect it'd generate
> __ANDROID__, but I don't see it in the output. 2) Building for android with
> distro toolchain doesn't make sense as it wouldn't have Bionic.

1) Did you build outside AOSP? If so,  I think it is reasonable since 
whatever __ANDROID__ or ANDROID are defined by Android build system 
instead of toolchain. I also tried to build the external/* thing and 
found ANDROID was actually generated. In my test, ANDROID seems to be 
the more suitable one, but in fact we can not build ltp inside AOSP 
because there is no Android.mk in ltp (please correct me if I am 
wrong...),  so ANDROID is meaningless to us here. Actually, this is why 
I think this patch is still useful, since __ANDROID__ is enough to 
distinguish what to compile if ANDROID=1 is set with make.

2) In the case of cross-compilation, I think it still makes sense, since 
we can use the same toolchain, such as clang,  and build parameters (the 
specify the include headers and libs, etc) as AOSP. This is what I am 
doing now, you can see my steps I posted in my previous reply. But in 
this case, we need to obviously set -D__ANDROID__ in CFLAGS. After that 
, the process should be similar as we launch a build inside AOSP.


Regards,

Zhengwang

>
> Kind regards,
> Petr
>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body smarttemplateinserted="true">
    <div id="smartTemplate4-template">
      <p> Hi Petr,<br>
      </p>
    </div>
    <br>
    <div id="smartTemplate4-quoteHeader">-------- Original Message --------<br>
      From: Petr Vorel<br>
      Sent: Fri, 12 Apr 2019 01:40:42 +0200<br>
      To: Sandeep Patil<br>
      Cc: Ltp<br>
      Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk: enable
      __ANDROID__ definition for Android b uild<br>
    </div>
    <blockquote type="cite" cite="mid:20190411234041.GB381@x230">
      <pre class="moz-quote-pre" wrap="">Hi Sandeep,

</pre>
      <blockquote type="cite">
        <blockquote type="cite">
          <blockquote type="cite">
            <blockquote type="cite">
              <pre class="moz-quote-pre" wrap="">-CFLAGS    += -Werror-implicit-function-declaration
+CFLAGS    += -Werror-implicit-function-declaration -D__ANDROID__
</pre>
            </blockquote>
            <pre class="moz-quote-pre" wrap="">Would adding __ANDROID__ definition help building LTP with distro
cross-compiler? (i.e. no NDK, no inside AOSP tree)?
I guess so and therefore, I'd be for this change.
I see some projects added it as well (busybox [1] [2], dnsmasq [3]).
BTW: where is defined for AOSP and NDK?
</pre>
          </blockquote>
        </blockquote>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">I think I've used __ANDROID__ and __BIONIC__ in the past for android-specific
things.  Honestly, I haven't tried to build for Android outside of AOSP tree
yet. I am happy to test this if you tell me how? (sorry for that.)
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">Great, thanks a lot!
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">According to [1] android toolchain (I guess both AOSP and NDK toolchain) define
__ANDROID__. Which is what I'd expect.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Grepping aosp only dnsmasq and swiftshader use -D__ANDROID__ (these are from
externals). -DANDROID is use more times (e.g. some drivers in hardware - ril,
qcom, libsensors and wpa_supplicant).
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">From my point of view, instead of -D__ANDROID__ or -DANDROID I'd prefer to to have
proper #ifdef HAVE_FOO guarders made by autotools checks. As android is not the
only minor libc. But I understand it's not always possible and we already use
some #ifdef __ANDROID__ in library sources and headers, so ack from myself to
help compilation outside AOSP and without NDK.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">Actually I was wrong. 1) I was using NDK toolchain. I'd expect it'd generate
__ANDROID__, but I don't see it in the output. 2) Building for android with
distro toolchain doesn't make sense as it wouldn't have Bionic.</pre>
    </blockquote>
    <p>1) Did you build outside AOSP? If so,  I think it is reasonable
      since whatever __ANDROID__ or ANDROID are defined by Android build
      system instead of toolchain. I also tried to build the external/*
      thing and found ANDROID was actually generated. In my test,
      ANDROID seems to be the more suitable one, but in fact we can not
      build ltp inside AOSP because there is no Android.mk in ltp
      (please correct me if I am wrong...),  so ANDROID is meaningless
      to us here. Actually, this is why I think this patch is still
      useful, since __ANDROID__ is enough to distinguish what to compile
      if ANDROID=1 is set with make.<br>
    </p>
    <p>2) In the case of cross-compilation, I think it still makes
      sense, since we can use the same toolchain, such as clang,  and
      build parameters (the specify the include headers and libs, etc)
      as AOSP. This is what I am doing now, you can see my steps I
      posted in my previous reply. But in this case, we need to
      obviously set -D__ANDROID__ in CFLAGS. After that , the process
      should be similar as we launch a build inside AOSP.</p>
    <p><br>
    </p>
    <p>Regards,</p>
    <p>Zhengwang<br>
    </p>
    <blockquote type="cite" cite="mid:20190411234041.GB381@x230">
      <pre class="moz-quote-pre" wrap="">

Kind regards,
Petr

</pre>
    </blockquote>
  </body>
</html>
Petr Vorel April 12, 2019, 6:28 a.m. UTC | #8
Hi Zhengwang,

> > > According to [1] android toolchain (I guess both AOSP and NDK toolchain) define
> > > __ANDROID__. Which is what I'd expect.
> > > Grepping aosp only dnsmasq and swiftshader use -D__ANDROID__ (these are from
> > > externals). -DANDROID is use more times (e.g. some drivers in hardware - ril,
> > > qcom, libsensors and wpa_supplicant).
> > >  From my point of view, instead of -D__ANDROID__ or -DANDROID I'd prefer to to have
> > > proper #ifdef HAVE_FOO guarders made by autotools checks. As android is not the
> > > only minor libc. But I understand it's not always possible and we already use
> > > some #ifdef __ANDROID__ in library sources and headers, so ack from myself to
> > > help compilation outside AOSP and without NDK.
> > Actually I was wrong. 1) I was using NDK toolchain. I'd expect it'd generate
> > __ANDROID__, but I don't see it in the output. 2) Building for android with
> > distro toolchain doesn't make sense as it wouldn't have Bionic.

> 1) Did you build outside AOSP? If so,  I think it is reasonable since
Yes, with android NDK (for Bionic and special toolchain tweeks).
Then I use ANDROID=1

> whatever __ANDROID__ or ANDROID are defined by Android build system instead
> of toolchain. I also tried to build the external/* thing and found ANDROID
> was actually generated. In my test, ANDROID seems to be the more suitable
> one, but in fact we can not build ltp inside AOSP because there is no
> Android.mk in ltp (please correct me if I am wrong...),  so ANDROID is
Yes, inside AOSP you need to use Android fork [1] which uses usual Android.bp.
Therefore AOSP does not use our build system.

> meaningless to us here. Actually, this is why I think this patch is still
> useful, since __ANDROID__ is enough to distinguish what to compile if
> ANDROID=1 is set with make.

> 2) In the case of cross-compilation, I think it still makes sense, since we
> can use the same toolchain, such as clang,  and build parameters (the
> specify the include headers and libs, etc) as AOSP. This is what I am doing
> now, you can see my steps I posted in my previous reply. But in this case,
> we need to obviously set -D__ANDROID__ in CFLAGS. After that , the process
> should be similar as we launch a build inside AOSP.
I don't know much about android toolchain, but IMHO there are some other tweaks
in their build system (to comply changes in Bionic), so not sure if it's even
possible to avoid using NDK for out-of-aosp tree. See also [2]. But that's a
question for for Android devs.

> Regards,

> Zhengwang

Kind regards,
Petr

[1] https://android.googlesource.com/platform/external/ltp/
[2] https://groups.google.com/forum/#!topic/android-ndk/cf9_f1SLXls
阮正旺 April 12, 2019, 4:15 p.m. UTC | #9
-------- Original Message --------
From: Petr Vorel
Sent: Fri, 12 Apr 2019 08:28:14 +0200
To: 阮正旺
Cc: Sandeep Patil, Ltp, Steve Muckle
Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable 
__ANDROID__ definition for Android build
> Hi Zhengwang,
>
>>>> According to [1] android toolchain (I guess both AOSP and NDK toolchain) define
>>>> __ANDROID__. Which is what I'd expect.
>>>> Grepping aosp only dnsmasq and swiftshader use -D__ANDROID__ (these are from
>>>> externals). -DANDROID is use more times (e.g. some drivers in hardware - ril,
>>>> qcom, libsensors and wpa_supplicant).
>>>>   From my point of view, instead of -D__ANDROID__ or -DANDROID I'd prefer to to have
>>>> proper #ifdef HAVE_FOO guarders made by autotools checks. As android is not the
>>>> only minor libc. But I understand it's not always possible and we already use
>>>> some #ifdef __ANDROID__ in library sources and headers, so ack from myself to
>>>> help compilation outside AOSP and without NDK.
>>> Actually I was wrong. 1) I was using NDK toolchain. I'd expect it'd generate
>>> __ANDROID__, but I don't see it in the output. 2) Building for android with
>>> distro toolchain doesn't make sense as it wouldn't have Bionic.
>> 1) Did you build outside AOSP? If so,  I think it is reasonable since
> Yes, with android NDK (for Bionic and special toolchain tweeks).
> Then I use ANDROID=1
>
>> whatever __ANDROID__ or ANDROID are defined by Android build system instead
>> of toolchain. I also tried to build the external/* thing and found ANDROID
>> was actually generated. In my test, ANDROID seems to be the more suitable
>> one, but in fact we can not build ltp inside AOSP because there is no
>> Android.mk in ltp (please correct me if I am wrong...),  so ANDROID is
> Yes, inside AOSP you need to use Android fork [1] which uses usual Android.bp.
> Therefore AOSP does not use our build system.
>
>> meaningless to us here. Actually, this is why I think this patch is still
>> useful, since __ANDROID__ is enough to distinguish what to compile if
>> ANDROID=1 is set with make.
>> 2) In the case of cross-compilation, I think it still makes sense, since we
>> can use the same toolchain, such as clang,  and build parameters (the
>> specify the include headers and libs, etc) as AOSP. This is what I am doing
>> now, you can see my steps I posted in my previous reply. But in this case,
>> we need to obviously set -D__ANDROID__ in CFLAGS. After that , the process
>> should be similar as we launch a build inside AOSP.
> I don't know much about android toolchain, but IMHO there are some other tweaks
> in their build system (to comply changes in Bionic), so not sure if it's even
> possible to avoid using NDK for out-of-aosp tree. See also [2]. But that's a
> question for for Android devs.

According to also [2], the situation gets clear now. All android targets 
should get __ANDROID__ defined by the compiler, but ANDROID only means 
'this is AOSP' and is only for Windows targets. In our case, __ANDROID__ 
should be preferred.


Regards,

Zhengwang

>
>> Regards,
>> Zhengwang
> Kind regards,
> Petr
>
> [1] https://android.googlesource.com/platform/external/ltp/
> [2] https://groups.google.com/forum/#!topic/android-ndk/cf9_f1SLXls
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body smarttemplateinserted="true">
    <div id="smartTemplate4-template">
      <p> </p>
    </div>
    <br>
    <div id="smartTemplate4-quoteHeader">-------- Original Message --------<br>
      From: Petr Vorel<br>
      Sent: Fri, 12 Apr 2019 08:28:14 +0200<br>
      To: 阮正旺<br>
      Cc: Sandeep Patil, Ltp, Steve Muckle<br>
      Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable
      __ANDROID__ definition for Android build<br>
    </div>
    <blockquote type="cite" cite="mid:20190412062814.GA18106@dell5510">
      <pre class="moz-quote-pre" wrap="">Hi Zhengwang,

</pre>
      <blockquote type="cite">
        <blockquote type="cite">
          <blockquote type="cite">
            <pre class="moz-quote-pre" wrap="">According to [1] android toolchain (I guess both AOSP and NDK toolchain) define
__ANDROID__. Which is what I'd expect.
Grepping aosp only dnsmasq and swiftshader use -D__ANDROID__ (these are from
externals). -DANDROID is use more times (e.g. some drivers in hardware - ril,
qcom, libsensors and wpa_supplicant).
 From my point of view, instead of -D__ANDROID__ or -DANDROID I'd prefer to to have
proper #ifdef HAVE_FOO guarders made by autotools checks. As android is not the
only minor libc. But I understand it's not always possible and we already use
some #ifdef __ANDROID__ in library sources and headers, so ack from myself to
help compilation outside AOSP and without NDK.
</pre>
          </blockquote>
          <pre class="moz-quote-pre" wrap="">Actually I was wrong. 1) I was using NDK toolchain. I'd expect it'd generate
__ANDROID__, but I don't see it in the output. 2) Building for android with
distro toolchain doesn't make sense as it wouldn't have Bionic.
</pre>
        </blockquote>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">1) Did you build outside AOSP? If so,  I think it is reasonable since
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">Yes, with android NDK (for Bionic and special toolchain tweeks).
Then I use ANDROID=1

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">whatever __ANDROID__ or ANDROID are defined by Android build system instead
of toolchain. I also tried to build the external/* thing and found ANDROID
was actually generated. In my test, ANDROID seems to be the more suitable
one, but in fact we can not build ltp inside AOSP because there is no
Android.mk in ltp (please correct me if I am wrong...),  so ANDROID is
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">Yes, inside AOSP you need to use Android fork [1] which uses usual Android.bp.
Therefore AOSP does not use our build system.

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">meaningless to us here. Actually, this is why I think this patch is still
useful, since __ANDROID__ is enough to distinguish what to compile if
ANDROID=1 is set with make.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">2) In the case of cross-compilation, I think it still makes sense, since we
can use the same toolchain, such as clang,  and build parameters (the
specify the include headers and libs, etc) as AOSP. This is what I am doing
now, you can see my steps I posted in my previous reply. But in this case,
we need to obviously set -D__ANDROID__ in CFLAGS. After that , the process
should be similar as we launch a build inside AOSP.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">I don't know much about android toolchain, but IMHO there are some other tweaks
in their build system (to comply changes in Bionic), so not sure if it's even
possible to avoid using NDK for out-of-aosp tree. See also [2]. But that's a
question for for Android devs.</pre>
    </blockquote>
    <p>According to also [2], the situation gets clear now. All android
      targets should get __ANDROID__ defined by the compiler, but
      ANDROID only means 'this is AOSP' and is only for Windows targets.
      In our case, __ANDROID__ should be preferred.</p>
    <p><br>
    </p>
    <p>Regards,</p>
    <p>Zhengwang<br>
    </p>
    <blockquote type="cite" cite="mid:20190412062814.GA18106@dell5510">
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Regards,
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Zhengwang
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
Kind regards,
Petr

[1] <a class="moz-txt-link-freetext" href="https://android.googlesource.com/platform/external/ltp/">https://android.googlesource.com/platform/external/ltp/</a>
[2] <a class="moz-txt-link-freetext" href="https://groups.google.com/forum/#!topic/android-ndk/cf9_f1SLXls">https://groups.google.com/forum/#!topic/android-ndk/cf9_f1SLXls</a>
</pre>
    </blockquote>
  </body>
</html>
Sandeep Patil April 12, 2019, 7:48 p.m. UTC | #10
On Sat, Apr 13, 2019 at 12:15:18AM +0800, 阮正旺 wrote:
> 
> -------- Original Message --------
> From: Petr Vorel
> Sent: Fri, 12 Apr 2019 08:28:14 +0200
> To: 阮正旺
> Cc: Sandeep Patil, Ltp, Steve Muckle
> Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable
> __ANDROID__ definition for Android build
> > Hi Zhengwang,
> > 
> > > > > According to [1] android toolchain (I guess both AOSP and NDK toolchain) define
> > > > > __ANDROID__. Which is what I'd expect.
> > > > > Grepping aosp only dnsmasq and swiftshader use -D__ANDROID__ (these are from
> > > > > externals). -DANDROID is use more times (e.g. some drivers in hardware - ril,
> > > > > qcom, libsensors and wpa_supplicant).
> > > > >   From my point of view, instead of -D__ANDROID__ or -DANDROID I'd prefer to to have
> > > > > proper #ifdef HAVE_FOO guarders made by autotools checks. As android is not the
> > > > > only minor libc. But I understand it's not always possible and we already use
> > > > > some #ifdef __ANDROID__ in library sources and headers, so ack from myself to
> > > > > help compilation outside AOSP and without NDK.
> > > > Actually I was wrong. 1) I was using NDK toolchain. I'd expect it'd generate
> > > > __ANDROID__, but I don't see it in the output. 2) Building for android with
> > > > distro toolchain doesn't make sense as it wouldn't have Bionic.
> > > 1) Did you build outside AOSP? If so,  I think it is reasonable since
> > Yes, with android NDK (for Bionic and special toolchain tweeks).
> > Then I use ANDROID=1
> > 
> > > whatever __ANDROID__ or ANDROID are defined by Android build system instead
> > > of toolchain. I also tried to build the external/* thing and found ANDROID
> > > was actually generated. In my test, ANDROID seems to be the more suitable
> > > one, but in fact we can not build ltp inside AOSP because there is no
> > > Android.mk in ltp (please correct me if I am wrong...),  so ANDROID is
> > Yes, inside AOSP you need to use Android fork [1] which uses usual Android.bp.
> > Therefore AOSP does not use our build system.
> > 
> > > meaningless to us here. Actually, this is why I think this patch is still
> > > useful, since __ANDROID__ is enough to distinguish what to compile if
> > > ANDROID=1 is set with make.
> > > 2) In the case of cross-compilation, I think it still makes sense, since we
> > > can use the same toolchain, such as clang,  and build parameters (the
> > > specify the include headers and libs, etc) as AOSP. This is what I am doing
> > > now, you can see my steps I posted in my previous reply. But in this case,
> > > we need to obviously set -D__ANDROID__ in CFLAGS. After that , the process
> > > should be similar as we launch a build inside AOSP.
> > I don't know much about android toolchain, but IMHO there are some other tweaks
> > in their build system (to comply changes in Bionic), so not sure if it's even
> > possible to avoid using NDK for out-of-aosp tree. See also [2]. But that's a
> > question for for Android devs.
> 
> According to also [2], the situation gets clear now. All android targets
> should get __ANDROID__ defined by the compiler, but ANDROID only means 'this
> is AOSP' and is only for Windows targets. In our case, __ANDROID__ should be
> preferred.

Correct, and the build can still be make ANDROID=1 which translates to
-D__ANDROID__.

JFYI, there have been occasions when we changed something in bionic as a
result of an LTP tests, so those fixes will be missing for someone who is
using ndk for testing and building LTP.

That being said, thats a fairly small subset and is manageable. We can catch
those in reviews / patches very easily.

I like the idea of being able to build ouf-of-aosp, so I'm going to give this
a try now and will report.

- ssp
> 
> 
> Regards,
> 
> Zhengwang
> 
> > 
> > > Regards,
> > > Zhengwang
> > Kind regards,
> > Petr
> > 
> > [1] https://android.googlesource.com/platform/external/ltp/
> > [2] https://groups.google.com/forum/#!topic/android-ndk/cf9_f1SLXls
阮正旺 April 16, 2019, 12:27 p.m. UTC | #11
Hi Sandeep,


-------- Original Message --------
From: Sandeep Patil
Sent: Fri, 12 Apr 2019 12:48:09 -0700
To: 阮正旺
Cc: Petr Vorel, Ltp, Steve Muckle
Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable 
__ANDROID__ definition for Android build
> On Sat, Apr 13, 2019 at 12:15:18AM +0800, 阮正旺 wrote:
>> -------- Original Message --------
>> From: Petr Vorel
>> Sent: Fri, 12 Apr 2019 08:28:14 +0200
>> To: 阮正旺
>> Cc: Sandeep Patil, Ltp, Steve Muckle
>> Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable
>> __ANDROID__ definition for Android build
>>> Hi Zhengwang,
>>>
>>>>>> According to [1] android toolchain (I guess both AOSP and NDK toolchain) define
>>>>>> __ANDROID__. Which is what I'd expect.
>>>>>> Grepping aosp only dnsmasq and swiftshader use -D__ANDROID__ (these are from
>>>>>> externals). -DANDROID is use more times (e.g. some drivers in hardware - ril,
>>>>>> qcom, libsensors and wpa_supplicant).
>>>>>>    From my point of view, instead of -D__ANDROID__ or -DANDROID I'd prefer to to have
>>>>>> proper #ifdef HAVE_FOO guarders made by autotools checks. As android is not the
>>>>>> only minor libc. But I understand it's not always possible and we already use
>>>>>> some #ifdef __ANDROID__ in library sources and headers, so ack from myself to
>>>>>> help compilation outside AOSP and without NDK.
>>>>> Actually I was wrong. 1) I was using NDK toolchain. I'd expect it'd generate
>>>>> __ANDROID__, but I don't see it in the output. 2) Building for android with
>>>>> distro toolchain doesn't make sense as it wouldn't have Bionic.
>>>> 1) Did you build outside AOSP? If so,  I think it is reasonable since
>>> Yes, with android NDK (for Bionic and special toolchain tweeks).
>>> Then I use ANDROID=1
>>>
>>>> whatever __ANDROID__ or ANDROID are defined by Android build system instead
>>>> of toolchain. I also tried to build the external/* thing and found ANDROID
>>>> was actually generated. In my test, ANDROID seems to be the more suitable
>>>> one, but in fact we can not build ltp inside AOSP because there is no
>>>> Android.mk in ltp (please correct me if I am wrong...),  so ANDROID is
>>> Yes, inside AOSP you need to use Android fork [1] which uses usual Android.bp.
>>> Therefore AOSP does not use our build system.
>>>
>>>> meaningless to us here. Actually, this is why I think this patch is still
>>>> useful, since __ANDROID__ is enough to distinguish what to compile if
>>>> ANDROID=1 is set with make.
>>>> 2) In the case of cross-compilation, I think it still makes sense, since we
>>>> can use the same toolchain, such as clang,  and build parameters (the
>>>> specify the include headers and libs, etc) as AOSP. This is what I am doing
>>>> now, you can see my steps I posted in my previous reply. But in this case,
>>>> we need to obviously set -D__ANDROID__ in CFLAGS. After that , the process
>>>> should be similar as we launch a build inside AOSP.
>>> I don't know much about android toolchain, but IMHO there are some other tweaks
>>> in their build system (to comply changes in Bionic), so not sure if it's even
>>> possible to avoid using NDK for out-of-aosp tree. See also [2]. But that's a
>>> question for for Android devs.
>> According to also [2], the situation gets clear now. All android targets
>> should get __ANDROID__ defined by the compiler, but ANDROID only means 'this
>> is AOSP' and is only for Windows targets. In our case, __ANDROID__ should be
>> preferred.
> Correct, and the build can still be make ANDROID=1 which translates to
> -D__ANDROID__.
>
> JFYI, there have been occasions when we changed something in bionic as a
> result of an LTP tests, so those fixes will be missing for someone who is
> using ndk for testing and building LTP.
>
> That being said, thats a fairly small subset and is manageable. We can catch
> those in reviews / patches very easily.
>
> I like the idea of being able to build ouf-of-aosp, so I'm going to give this
> a try now and will report.

Have you tried to build out-of-aosp? :-)


Regards,

Zhengwang

> - ssp
>>
>> Regards,
>>
>> Zhengwang
>>
>>>> Regards,
>>>> Zhengwang
>>> Kind regards,
>>> Petr
>>>
>>> [1] https://android.googlesource.com/platform/external/ltp/
>>> [2] https://groups.google.com/forum/#!topic/android-ndk/cf9_f1SLXls
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body smarttemplateinserted="true">
    <div id="smartTemplate4-template">
      <p> Hi Sandeep,<br>
      </p>
    </div>
    <br>
    <div id="smartTemplate4-quoteHeader">-------- Original Message --------<br>
      From: Sandeep Patil<br>
      Sent: Fri, 12 Apr 2019 12:48:09 -0700<br>
      To: 阮正旺<br>
      Cc: Petr Vorel, Ltp, Steve Muckle<br>
      Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable
      __ANDROID__ definition for Android build<br>
    </div>
    <blockquote type="cite"
      cite="mid:20190412194809.GE124555@google.com">
      <pre class="moz-quote-pre" wrap="">On Sat, Apr 13, 2019 at 12:15:18AM +0800, 阮正旺 wrote:
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">
-------- Original Message --------
From: Petr Vorel
Sent: Fri, 12 Apr 2019 08:28:14 +0200
To: 阮正旺
Cc: Sandeep Patil, Ltp, Steve Muckle
Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable
__ANDROID__ definition for Android build
</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">Hi Zhengwang,

</pre>
          <blockquote type="cite">
            <blockquote type="cite">
              <blockquote type="cite">
                <pre class="moz-quote-pre" wrap="">According to [1] android toolchain (I guess both AOSP and NDK toolchain) define
__ANDROID__. Which is what I'd expect.
Grepping aosp only dnsmasq and swiftshader use -D__ANDROID__ (these are from
externals). -DANDROID is use more times (e.g. some drivers in hardware - ril,
qcom, libsensors and wpa_supplicant).
  From my point of view, instead of -D__ANDROID__ or -DANDROID I'd prefer to to have
proper #ifdef HAVE_FOO guarders made by autotools checks. As android is not the
only minor libc. But I understand it's not always possible and we already use
some #ifdef __ANDROID__ in library sources and headers, so ack from myself to
help compilation outside AOSP and without NDK.
</pre>
              </blockquote>
              <pre class="moz-quote-pre" wrap="">Actually I was wrong. 1) I was using NDK toolchain. I'd expect it'd generate
__ANDROID__, but I don't see it in the output. 2) Building for android with
distro toolchain doesn't make sense as it wouldn't have Bionic.
</pre>
            </blockquote>
            <pre class="moz-quote-pre" wrap="">1) Did you build outside AOSP? If so,  I think it is reasonable since
</pre>
          </blockquote>
          <pre class="moz-quote-pre" wrap="">Yes, with android NDK (for Bionic and special toolchain tweeks).
Then I use ANDROID=1

</pre>
          <blockquote type="cite">
            <pre class="moz-quote-pre" wrap="">whatever __ANDROID__ or ANDROID are defined by Android build system instead
of toolchain. I also tried to build the external/* thing and found ANDROID
was actually generated. In my test, ANDROID seems to be the more suitable
one, but in fact we can not build ltp inside AOSP because there is no
Android.mk in ltp (please correct me if I am wrong...),  so ANDROID is
</pre>
          </blockquote>
          <pre class="moz-quote-pre" wrap="">Yes, inside AOSP you need to use Android fork [1] which uses usual Android.bp.
Therefore AOSP does not use our build system.

</pre>
          <blockquote type="cite">
            <pre class="moz-quote-pre" wrap="">meaningless to us here. Actually, this is why I think this patch is still
useful, since __ANDROID__ is enough to distinguish what to compile if
ANDROID=1 is set with make.
2) In the case of cross-compilation, I think it still makes sense, since we
can use the same toolchain, such as clang,  and build parameters (the
specify the include headers and libs, etc) as AOSP. This is what I am doing
now, you can see my steps I posted in my previous reply. But in this case,
we need to obviously set -D__ANDROID__ in CFLAGS. After that , the process
should be similar as we launch a build inside AOSP.
</pre>
          </blockquote>
          <pre class="moz-quote-pre" wrap="">I don't know much about android toolchain, but IMHO there are some other tweaks
in their build system (to comply changes in Bionic), so not sure if it's even
possible to avoid using NDK for out-of-aosp tree. See also [2]. But that's a
question for for Android devs.
</pre>
        </blockquote>
        <pre class="moz-quote-pre" wrap="">
According to also [2], the situation gets clear now. All android targets
should get __ANDROID__ defined by the compiler, but ANDROID only means 'this
is AOSP' and is only for Windows targets. In our case, __ANDROID__ should be
preferred.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
Correct, and the build can still be make ANDROID=1 which translates to
-D__ANDROID__.

JFYI, there have been occasions when we changed something in bionic as a
result of an LTP tests, so those fixes will be missing for someone who is
using ndk for testing and building LTP.

That being said, thats a fairly small subset and is manageable. We can catch
those in reviews / patches very easily.

I like the idea of being able to build ouf-of-aosp, so I'm going to give this
a try now and will report.
</pre>
    </blockquote>
    <p>Have you tried to build out-of-aosp? :-)</p>
    <p><br>
    </p>
    <p>Regards,</p>
    <p>Zhengwang<br>
    </p>
    <blockquote type="cite"
      cite="mid:20190412194809.GE124555@google.com">
      <pre class="moz-quote-pre" wrap="">
- ssp
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">

Regards,

Zhengwang

</pre>
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">
</pre>
          <blockquote type="cite">
            <pre class="moz-quote-pre" wrap="">Regards,
Zhengwang
</pre>
          </blockquote>
          <pre class="moz-quote-pre" wrap="">Kind regards,
Petr

[1] <a class="moz-txt-link-freetext" href="https://android.googlesource.com/platform/external/ltp/">https://android.googlesource.com/platform/external/ltp/</a>
[2] <a class="moz-txt-link-freetext" href="https://groups.google.com/forum/#!topic/android-ndk/cf9_f1SLXls">https://groups.google.com/forum/#!topic/android-ndk/cf9_f1SLXls</a>
</pre>
        </blockquote>
      </blockquote>
    </blockquote>
  </body>
</html>
Sandeep Patil April 17, 2019, 4:39 p.m. UTC | #12
On Tue, Apr 16, 2019 at 08:27:24PM +0800, 阮正旺 wrote:
>  Hi Sandeep,
> 
> 
> -------- Original Message --------
> From: Sandeep Patil
> Sent: Fri, 12 Apr 2019 12:48:09 -0700
> To: 阮正旺
> Cc: Petr Vorel, Ltp, Steve Muckle
> Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable
> __ANDROID__ definition for Android build
> > On Sat, Apr 13, 2019 at 12:15:18AM +0800, 阮正旺 wrote:
> > > -------- Original Message --------
> > > From: Petr Vorel
> > > Sent: Fri, 12 Apr 2019 08:28:14 +0200
> > > To: 阮正旺
> > > Cc: Sandeep Patil, Ltp, Steve Muckle
> > > Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable
> > > __ANDROID__ definition for Android build
> > > > Hi Zhengwang,
> > > > 
> > > > > > > According to [1] android toolchain (I guess both AOSP and NDK toolchain) define
> > > > > > > __ANDROID__. Which is what I'd expect.
> > > > > > > Grepping aosp only dnsmasq and swiftshader use -D__ANDROID__ (these are from
> > > > > > > externals). -DANDROID is use more times (e.g. some drivers in hardware - ril,
> > > > > > > qcom, libsensors and wpa_supplicant).
> > > > > > >    From my point of view, instead of -D__ANDROID__ or -DANDROID I'd prefer to to have
> > > > > > > proper #ifdef HAVE_FOO guarders made by autotools checks. As android is not the
> > > > > > > only minor libc. But I understand it's not always possible and we already use
> > > > > > > some #ifdef __ANDROID__ in library sources and headers, so ack from myself to
> > > > > > > help compilation outside AOSP and without NDK.
> > > > > > Actually I was wrong. 1) I was using NDK toolchain. I'd expect it'd generate
> > > > > > __ANDROID__, but I don't see it in the output. 2) Building for android with
> > > > > > distro toolchain doesn't make sense as it wouldn't have Bionic.
> > > > > 1) Did you build outside AOSP? If so,  I think it is reasonable since
> > > > Yes, with android NDK (for Bionic and special toolchain tweeks).
> > > > Then I use ANDROID=1
> > > > 
> > > > > whatever __ANDROID__ or ANDROID are defined by Android build system instead
> > > > > of toolchain. I also tried to build the external/* thing and found ANDROID
> > > > > was actually generated. In my test, ANDROID seems to be the more suitable
> > > > > one, but in fact we can not build ltp inside AOSP because there is no
> > > > > Android.mk in ltp (please correct me if I am wrong...),  so ANDROID is
> > > > Yes, inside AOSP you need to use Android fork [1] which uses usual Android.bp.
> > > > Therefore AOSP does not use our build system.
> > > > 
> > > > > meaningless to us here. Actually, this is why I think this patch is still
> > > > > useful, since __ANDROID__ is enough to distinguish what to compile if
> > > > > ANDROID=1 is set with make.
> > > > > 2) In the case of cross-compilation, I think it still makes sense, since we
> > > > > can use the same toolchain, such as clang,  and build parameters (the
> > > > > specify the include headers and libs, etc) as AOSP. This is what I am doing
> > > > > now, you can see my steps I posted in my previous reply. But in this case,
> > > > > we need to obviously set -D__ANDROID__ in CFLAGS. After that , the process
> > > > > should be similar as we launch a build inside AOSP.
> > > > I don't know much about android toolchain, but IMHO there are some other tweaks
> > > > in their build system (to comply changes in Bionic), so not sure if it's even
> > > > possible to avoid using NDK for out-of-aosp tree. See also [2]. But that's a
> > > > question for for Android devs.
> > > According to also [2], the situation gets clear now. All android targets
> > > should get __ANDROID__ defined by the compiler, but ANDROID only means 'this
> > > is AOSP' and is only for Windows targets. In our case, __ANDROID__ should be
> > > preferred.
> > Correct, and the build can still be make ANDROID=1 which translates to
> > -D__ANDROID__.
> > 
> > JFYI, there have been occasions when we changed something in bionic as a
> > result of an LTP tests, so those fixes will be missing for someone who is
> > using ndk for testing and building LTP.
> > 
> > That being said, thats a fairly small subset and is manageable. We can catch
> > those in reviews / patches very easily.
> > 
> > I like the idea of being able to build ouf-of-aosp, so I'm going to give this
> > a try now and will report.
> 
> Have you tried to build out-of-aosp? :-)

Yes, I did that now and ran into a build error with pread02 pasted at the
end of this email.

This was much easier than I thought and I think I can start sending trivial
fixes as I go. Here's what I did.

1. Download the ndk20 beta from - https://developer.android.com/ndk/downloads
2. Set up ndk toolchains for autoconf as shown in
   https://developer.android.com/ndk/guides/other_build_systems#autoconf
3. In LTP, do
   $ ./configure --host x86_64-linux-android --prefix=<preferred install location>
   $ make ANDROID=1

Please let me know if this doesn't sound right? It seems a lot easier than
the steps pasted earlier.

- ssp


======================

/usr/local/google/home/sspatil/bin/android-ndk-r20-beta2/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android28-clang -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -Werror-implicit-function-declaration -D_FORTIFY_SOURCE=2 -I/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls/preadv -I/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls/preadv/../utils -I../../../../include -I../../../../include -I../../../../include/old/   -L../../../../lib -L../../../../lib/android_libpthread -L../../../../lib/android_librt  preadv02.c   -lltp -o preadv02
preadv02.c:89:7: error: implicit declaration of function 'preadv' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        TEST(preadv(*tc->fd, tc->name, tc->count, tc->offset));
             ^
1 error generated.
<builtin>: recipe for target 'preadv02' failed
make[4]: *** [preadv02] Error 1
make[4]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls/preadv'
../../../include/mk/generic_trunk_target.inc:93: recipe for target 'all' failed
make[3]: *** [all] Error 2
make[3]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls'
../../include/mk/generic_trunk_target.inc:93: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel'
../include/mk/generic_trunk_target.inc:93: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases'
Makefile:111: recipe for target 'testcases-all' failed
make: *** [testcases-all] Error 2
Petr Vorel April 17, 2019, 5:06 p.m. UTC | #13
Hi Sandeep,

> > Have you tried to build out-of-aosp? :-)

> Yes, I did that now and ran into a build error with pread02 pasted at the
> end of this email.

> This was much easier than I thought and I think I can start sending trivial
> fixes as I go. Here's what I did.

> 1. Download the ndk20 beta from - https://developer.android.com/ndk/downloads
> 2. Set up ndk toolchains for autoconf as shown in
>    https://developer.android.com/ndk/guides/other_build_systems#autoconf
Thanks for a hint. I was using standalone toolchain [1], created with NKD r19,
but see according a doc that it was deprecated even for r19.

[1] https://developer.android.com/ndk/guides/standalone_toolchain

> 3. In LTP, do
>    $ ./configure --host x86_64-linux-android --prefix=<preferred install location>
>    $ make ANDROID=1

I'm also passing these flags to CFLAGS, but it might not be necessary:
 --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include

for arm host I use:
--host arm-linux-androideabi

and also define CROSS_COMPILE + other variables:
export CROSS_COMPILE=$TOOLCHAIN_ROOT/bin/arm-linux-androideabi-
export AR=${CROSS_COMPILE}ar
export AS=${CROSS_COMPILE}as
export NM=${CROSS_COMPILE}nm
export CC=${CROSS_COMPILE}gcc
export LD=${CROSS_COMPILE}ld
export RANLIB=${CROSS_COMPILE}ranlib

Only CROSS_COMPILE should be needed as, others are in
include/mk/config.mk.default, but my toolchain setup does not detect them
(include/mk/config.mk does not have cross-compile versions)

> Please let me know if this doesn't sound right? It seems a lot easier than
> the steps pasted earlier.

> - ssp


> ======================

> /usr/local/google/home/sspatil/bin/android-ndk-r20-beta2/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android28-clang -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -Werror-implicit-function-declaration -D_FORTIFY_SOURCE=2 -I/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls/preadv -I/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls/preadv/../utils -I../../../../include -I../../../../include -I../../../../include/old/   -L../../../../lib -L../../../../lib/android_libpthread -L../../../../lib/android_librt  preadv02.c   -lltp -o preadv02
> preadv02.c:89:7: error: implicit declaration of function 'preadv' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
>         TEST(preadv(*tc->fd, tc->name, tc->count, tc->offset));
>              ^
I bump into the same problem

+ this one:
pwritev02.c:85:7: error: implicit declaration of function 'pwritev' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        TEST(pwritev(*tc->fd, tc->name, tc->count, tc->offset));

So for the build is needed to comment out HAVE_PREADV and HAVE_PWRITEV
definitions in include/config.h.

I don't know why autotools fails preadv and pwritev detection with AC_CHECK_FUNCS.
I considered it as problem of my setup, but maybe it's an autotools bug.

> 1 error generated.
> <builtin>: recipe for target 'preadv02' failed
> make[4]: *** [preadv02] Error 1
> make[4]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls/preadv'
> ../../../include/mk/generic_trunk_target.inc:93: recipe for target 'all' failed
> make[3]: *** [all] Error 2
> make[3]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls'
> ../../include/mk/generic_trunk_target.inc:93: recipe for target 'all' failed
> make[2]: *** [all] Error 2
> make[2]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel'
> ../include/mk/generic_trunk_target.inc:93: recipe for target 'all' failed
> make[1]: *** [all] Error 2
> make[1]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases'
> Makefile:111: recipe for target 'testcases-all' failed
> make: *** [testcases-all] Error 2


Kind regards,
Petr
阮正旺 April 19, 2019, 3:49 p.m. UTC | #14
Hi Sandeep, Petr,


-------- Original Message --------
From: Petr Vorel
Sent: Wed, 17 Apr 2019 19:06:51 +0200
To: Sandeep Patil
Cc: Zhengwang Ruan, Ltp, Steve Muckle
Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable 
__ANDROID__ definition for Android build
> Hi Sandeep,
>
>>> Have you tried to build out-of-aosp? :-)
>> Yes, I did that now and ran into a build error with pread02 pasted at the
>> end of this email.
>> This was much easier than I thought and I think I can start sending trivial
>> fixes as I go. Here's what I did.
>> 1. Download the ndk20 beta from - https://developer.android.com/ndk/downloads
>> 2. Set up ndk toolchains for autoconf as shown in
>>     https://developer.android.com/ndk/guides/other_build_systems#autoconf
> Thanks for a hint. I was using standalone toolchain [1], created with NKD r19,
> but see according a doc that it was deprecated even for r19.
>
> [1] https://developer.android.com/ndk/guides/standalone_toolchain
>
>> 3. In LTP, do
>>     $ ./configure --host x86_64-linux-android --prefix=<preferred install location>
>>     $ make ANDROID=1
> I'm also passing these flags to CFLAGS, but it might not be necessary:
>   --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include
>
> for arm host I use:
> --host arm-linux-androideabi
>
> and also define CROSS_COMPILE + other variables:
> export CROSS_COMPILE=$TOOLCHAIN_ROOT/bin/arm-linux-androideabi-
> export AR=${CROSS_COMPILE}ar
> export AS=${CROSS_COMPILE}as
> export NM=${CROSS_COMPILE}nm
> export CC=${CROSS_COMPILE}gcc
> export LD=${CROSS_COMPILE}ld
> export RANLIB=${CROSS_COMPILE}ranlib
>
> Only CROSS_COMPILE should be needed as, others are in
> include/mk/config.mk.default, but my toolchain setup does not detect them
> (include/mk/config.mk does not have cross-compile versions)
>
>> Please let me know if this doesn't sound right? It seems a lot easier than
>> the steps pasted earlier.
>> - ssp
>
>> ======================
>> /usr/local/google/home/sspatil/bin/android-ndk-r20-beta2/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android28-clang -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -Werror-implicit-function-declaration -D_FORTIFY_SOURCE=2 -I/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls/preadv -I/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls/preadv/../utils -I../../../../include -I../../../../include -I../../../../include/old/   -L../../../../lib -L../../../../lib/android_libpthread -L../../../../lib/android_librt  preadv02.c   -lltp -o preadv02
>> preadv02.c:89:7: error: implicit declaration of function 'preadv' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
>>          TEST(preadv(*tc->fd, tc->name, tc->count, tc->offset));
>>               ^
> I bump into the same problem
>
> + this one:
> pwritev02.c:85:7: error: implicit declaration of function 'pwritev' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
>          TEST(pwritev(*tc->fd, tc->name, tc->count, tc->offset));
>
> So for the build is needed to comment out HAVE_PREADV and HAVE_PWRITEV
> definitions in include/config.h.
>
> I don't know why autotools fails preadv and pwritev detection with AC_CHECK_FUNCS.
> I considered it as problem of my setup, but maybe it's an autotools bug.

I also encountered this issue, but I temporarily walked around it by 
applying the following patch.

==================

$ git diff testcases/
diff --git a/testcases/commands/ldd/datafiles/Makefile 
b/testcases/commands/ldd/datafiles/Makefile
index d8bcf5c..74fbe50 100644
--- a/testcases/commands/ldd/datafiles/Makefile
+++ b/testcases/commands/ldd/datafiles/Makefile
@@ -30,7 +30,7 @@ CLEAN_TARGETS         += *.obj $(LDD_SO_FILES)
         $(CC) $(CFLAGS) -shared -o $@ $^

  lddfile.out: main.o $(LDD_SO_FILES)
-       $(CC) $(CFLAGS) -O -o $@ $?
+       $(CC) $(CFLAGS) $(LDFLAGS) -O -o $@ $?

  INSTALL_DIR            := testcases/data/ldd01

diff --git a/testcases/kernel/syscalls/Makefile 
b/testcases/kernel/syscalls/Makefile
index 45a00cf..27c2e7a 100644
--- a/testcases/kernel/syscalls/Makefile
+++ b/testcases/kernel/syscalls/Makefile
@@ -43,6 +43,8 @@ FILTER_OUT_DIRS       += \
         sched_getaffinity sched_setaffinity sendmsg setgroups setns 
sighold \
         sigrelse sigsuspend sigtimedwait sigwait sigwaitinfo stime \
         setdomainname sethostname symlinkat ulimit ustat vfork vhangup 
vmsplice
+
+FILTER_OUT_DIRS += preadv pwritev
  endif

==========

Then I can accomplish compiling LTP with android-ndk-r19c, and my 
configure as below.

==============

$ export NDK_TOOL_DIR=/path/to/android-ndk-r19c

$ ./configure --prefix=/tmp/ltp 
CC=${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang 
AR=${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar 
CFLAGS="-isystem ${NDK_TOOL_DIR}/sysroot/usr/include -I 
/media/Workspace/Softwares/Linux/toolschain/ndk/android-ndk-r19c/sysroot/usr/include 
-I 
/media/Workspace/Softwares/Linux/toolschain/ndk/android-ndk-r19c/sysroot/usr/include/aarch64-linux-android 
-D__ANDROID__ -fmessage-length=0 -W -Wall -Wno-unused -Winit-self 
-Wpointer-arith -no-canonical-prefixes -DNDEBUG -UDEBUG -fno-exceptions 
-Wno-multichar -O2 -g -fno-strict-aliasing 
-fdebug-prefix-map=/proc/self/cwd= 
-D__compiler_offsetof=__builtin_offsetof -Werror=int-conversion 
-Wno-reserved-id-macro -Wno-format-pedantic 
-Wno-unused-command-line-argument -fcolor-diagnostics 
-Wno-expansion-to-defined -Wno-zero-as-null-pointer-constant 
-ffunction-sections -fdata-sections -fno-short-enums -funwind-tables 
-fstack-protector-strong -Wa,--noexecstack -D_FORTIFY_SOURCE=2 
-Wstrict-aliasing=2 -Werror=return-type -Werror=non-virtual-dtor 
-Werror=address -Werror=sequence-point -Werror=date-time 
-Werror=format-security -nostdlibinc -march=armv8-a  -target 
aarch64-linux-android 
-B${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin -std=gnu99 
-Wall -fPIE -D_USING_LIBCXX -Werror=int-to-pointer-cast 
-Werror=pointer-to-int-cast -Werror=address-of-temporary 
-Werror=return-type -Wno-tautological-constant-compare 
-Wno-null-pointer-arithmetic -Wno-enum-compare -Wno-enum-compare-switch 
-MD -nostdlib -pthread" --host=aarch64-linux-gnu LDFLAGS="-nostdlib 
-Wl,-dynamic-linker,/system/bin/linker64 -Wl,--gc-sections 
-Wl,-z,nocopyreloc 
-Wl,-rpath-link=${BUILD_PROJ_DIR}/out/target/product/e28/obj/lib 
${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/28/crtbegin_dynamic.o 
-Wl,--whole-archive  -Wl,--no-whole-archive 
${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.2/lib/linux/libclang_rt.ubsan_minimal-aarch64-android.a 
${NDK_TOOL_DIR}/sysroot/usr/lib/aarch64-linux-android/libcompiler_rt-extras.a 
${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/lib64/libatomic.a 
${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/libgcc.a 
-Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5 
-Wl,--warn-shared-textrel -Wl,--fatal-warnings 
-Wl,--no-undefined-version -Wl,-m,aarch64_elf64_le_vec 
-Wl,--hash-style=gnu -fuse-ld=gold -Wl,--icf=safe 
-Wl,--exclude-libs,libclang_rt.ubsan_minimal-aarch64-android.a 
-Wl,--no-undefined 
-B${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin 
-L${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/28 
-lc++ -lc -lm -ldl 
${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/28/crtend_android.o 
-target aarch64-linux-android"

$ make ANDROID=1


Regards,

Zhengwang

>> 1 error generated.
>> <builtin>: recipe for target 'preadv02' failed
>> make[4]: *** [preadv02] Error 1
>> make[4]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls/preadv'
>> ../../../include/mk/generic_trunk_target.inc:93: recipe for target 'all' failed
>> make[3]: *** [all] Error 2
>> make[3]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls'
>> ../../include/mk/generic_trunk_target.inc:93: recipe for target 'all' failed
>> make[2]: *** [all] Error 2
>> make[2]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel'
>> ../include/mk/generic_trunk_target.inc:93: recipe for target 'all' failed
>> make[1]: *** [all] Error 2
>> make[1]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases'
>> Makefile:111: recipe for target 'testcases-all' failed
>> make: *** [testcases-all] Error 2
>
> Kind regards,
> Petr
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body smarttemplateinserted="true">
    <div id="smartTemplate4-template">
      <p>Hi Sandeep, Petr, <br>
      </p>
    </div>
    <br>
    <div id="smartTemplate4-quoteHeader">-------- Original Message --------<br>
      From: Petr Vorel<br>
      Sent: Wed, 17 Apr 2019 19:06:51 +0200<br>
      To: Sandeep Patil<br>
      Cc: Zhengwang Ruan, Ltp, Steve Muckle<br>
      Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable
      __ANDROID__ definition for Android build<br>
    </div>
    <blockquote type="cite" cite="mid:20190417170651.GA26229@x230">
      <pre class="moz-quote-pre" wrap="">Hi Sandeep,

</pre>
      <blockquote type="cite">
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">Have you tried to build out-of-aosp? :-)
</pre>
        </blockquote>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Yes, I did that now and ran into a build error with pread02 pasted at the
end of this email.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">This was much easier than I thought and I think I can start sending trivial
fixes as I go. Here's what I did.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">1. Download the ndk20 beta from - <a class="moz-txt-link-freetext" href="https://developer.android.com/ndk/downloads">https://developer.android.com/ndk/downloads</a>
2. Set up ndk toolchains for autoconf as shown in
   <a class="moz-txt-link-freetext" href="https://developer.android.com/ndk/guides/other_build_systems#autoconf">https://developer.android.com/ndk/guides/other_build_systems#autoconf</a>
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">Thanks for a hint. I was using standalone toolchain [1], created with NKD r19,
but see according a doc that it was deprecated even for r19.

[1] <a class="moz-txt-link-freetext" href="https://developer.android.com/ndk/guides/standalone_toolchain">https://developer.android.com/ndk/guides/standalone_toolchain</a>

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">3. In LTP, do
   $ ./configure --host x86_64-linux-android --prefix=&lt;preferred install location&gt;
   $ make ANDROID=1
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
I'm also passing these flags to CFLAGS, but it might not be necessary:
 --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include

for arm host I use:
--host arm-linux-androideabi

and also define CROSS_COMPILE + other variables:
export CROSS_COMPILE=$TOOLCHAIN_ROOT/bin/arm-linux-androideabi-
export AR=${CROSS_COMPILE}ar
export AS=${CROSS_COMPILE}as
export NM=${CROSS_COMPILE}nm
export CC=${CROSS_COMPILE}gcc
export LD=${CROSS_COMPILE}ld
export RANLIB=${CROSS_COMPILE}ranlib

Only CROSS_COMPILE should be needed as, others are in
include/mk/config.mk.default, but my toolchain setup does not detect them
(include/mk/config.mk does not have cross-compile versions)

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Please let me know if this doesn't sound right? It seems a lot easier than
the steps pasted earlier.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">- ssp
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">======================
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">/usr/local/google/home/sspatil/bin/android-ndk-r20-beta2/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android28-clang -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -Werror-implicit-function-declaration -D_FORTIFY_SOURCE=2 -I/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls/preadv -I/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls/preadv/../utils -I../../../../include -I../../../../include -I../../../../include/old/   -L../../../../lib -L../../../../lib/android_libpthread -L../../../../lib/android_librt  preadv02.c   -lltp -o preadv02
preadv02.c:89:7: error: implicit declaration of function 'preadv' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        TEST(preadv(*tc-&gt;fd, tc-&gt;name, tc-&gt;count, tc-&gt;offset));
             ^
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">I bump into the same problem

+ this one:
pwritev02.c:85:7: error: implicit declaration of function 'pwritev' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        TEST(pwritev(*tc-&gt;fd, tc-&gt;name, tc-&gt;count, tc-&gt;offset));

So for the build is needed to comment out HAVE_PREADV and HAVE_PWRITEV
definitions in include/config.h.

I don't know why autotools fails preadv and pwritev detection with AC_CHECK_FUNCS.
I considered it as problem of my setup, but maybe it's an autotools bug.
</pre>
    </blockquote>
    <p>I also encountered this issue, but I temporarily walked around it
      by applying the following patch.</p>
    <p>==================<br>
    </p>
    <p>$ git diff testcases/<br>
      diff --git a/testcases/commands/ldd/datafiles/Makefile
      b/testcases/commands/ldd/datafiles/Makefile<br>
      index d8bcf5c..74fbe50 100644<br>
      --- a/testcases/commands/ldd/datafiles/Makefile<br>
      +++ b/testcases/commands/ldd/datafiles/Makefile<br>
      @@ -30,7 +30,7 @@ CLEAN_TARGETS         += *.obj $(LDD_SO_FILES)<br>
              $(CC) $(CFLAGS) -shared -o $@ $^<br>
       <br>
       lddfile.out: main.o $(LDD_SO_FILES)<br>
      -       $(CC) $(CFLAGS) -O -o $@ $?<br>
      +       $(CC) $(CFLAGS) $(LDFLAGS) -O -o $@ $?<br>
       <br>
       INSTALL_DIR            := testcases/data/ldd01<br>
       <br>
      diff --git a/testcases/kernel/syscalls/Makefile
      b/testcases/kernel/syscalls/Makefile<br>
      index 45a00cf..27c2e7a 100644<br>
      --- a/testcases/kernel/syscalls/Makefile<br>
      +++ b/testcases/kernel/syscalls/Makefile<br>
      @@ -43,6 +43,8 @@ FILTER_OUT_DIRS       += \<br>
              sched_getaffinity sched_setaffinity sendmsg setgroups
      setns sighold \<br>
              sigrelse sigsuspend sigtimedwait sigwait sigwaitinfo stime
      \<br>
              setdomainname sethostname symlinkat ulimit ustat vfork
      vhangup vmsplice<br>
      +<br>
      +FILTER_OUT_DIRS += preadv pwritev<br>
       endif<br>
    </p>
    <p>==========</p>
    <p>Then I can accomplish compiling LTP with android-ndk-r19c, and my
      configure as below.</p>
    <p>==============</p>
    <p>$ export NDK_TOOL_DIR=/path/to/android-ndk-r19c</p>
    <p>$ ./configure --prefix=/tmp/ltp
      CC=${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
AR=${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
      CFLAGS="-isystem ${NDK_TOOL_DIR}/sysroot/usr/include -I
/media/Workspace/Softwares/Linux/toolschain/ndk/android-ndk-r19c/sysroot/usr/include
      -I
/media/Workspace/Softwares/Linux/toolschain/ndk/android-ndk-r19c/sysroot/usr/include/aarch64-linux-android
      <font color="#cc0000">-D__ANDROID__ </font>-fmessage-length=0 -W
      -Wall -Wno-unused -Winit-self -Wpointer-arith
      -no-canonical-prefixes -DNDEBUG -UDEBUG -fno-exceptions
      -Wno-multichar -O2 -g -fno-strict-aliasing
      -fdebug-prefix-map=/proc/self/cwd=
      -D__compiler_offsetof=__builtin_offsetof -Werror=int-conversion
      -Wno-reserved-id-macro -Wno-format-pedantic
      -Wno-unused-command-line-argument -fcolor-diagnostics
      -Wno-expansion-to-defined -Wno-zero-as-null-pointer-constant
      -ffunction-sections -fdata-sections -fno-short-enums
      -funwind-tables -fstack-protector-strong -Wa,--noexecstack
      -D_FORTIFY_SOURCE=2 -Wstrict-aliasing=2 -Werror=return-type
      -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point
      -Werror=date-time -Werror=format-security -nostdlibinc
      -march=armv8-a  -target aarch64-linux-android
      -B${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin
      -std=gnu99 -Wall -fPIE -D_USING_LIBCXX -Werror=int-to-pointer-cast
      -Werror=pointer-to-int-cast -Werror=address-of-temporary
      -Werror=return-type -Wno-tautological-constant-compare
      -Wno-null-pointer-arithmetic -Wno-enum-compare
      -Wno-enum-compare-switch -MD -nostdlib -pthread"
      --host=aarch64-linux-gnu LDFLAGS="-nostdlib
      -Wl,-dynamic-linker,/system/bin/linker64 -Wl,--gc-sections
      -Wl,-z,nocopyreloc
      -Wl,-rpath-link=${BUILD_PROJ_DIR}/out/target/product/e28/obj/lib
${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/28/crtbegin_dynamic.o
      -Wl,--whole-archive  -Wl,--no-whole-archive  
${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/8.0.2/lib/linux/libclang_rt.ubsan_minimal-aarch64-android.a 
${NDK_TOOL_DIR}/sysroot/usr/lib/aarch64-linux-android/libcompiler_rt-extras.a
${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/lib64/libatomic.a
${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/lib/gcc/aarch64-linux-android/4.9.x/libgcc.a
      -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5
      -Wl,--warn-shared-textrel -Wl,--fatal-warnings
      -Wl,--no-undefined-version -Wl,-m,aarch64_elf64_le_vec
      -Wl,--hash-style=gnu -fuse-ld=gold -Wl,--icf=safe
      -Wl,--exclude-libs,libclang_rt.ubsan_minimal-aarch64-android.a
      -Wl,--no-undefined
      -B${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/bin
-L${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/28
      -lc++ -lc -lm -ldl
${NDK_TOOL_DIR}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/28/crtend_android.o
      -target aarch64-linux-android"</p>
    <p>$ make ANDROID=1<br>
    </p>
    <p><br>
    </p>
    <p>Regards,</p>
    <p>Zhengwang<br>
    </p>
    <blockquote type="cite" cite="mid:20190417170651.GA26229@x230">
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">1 error generated.
&lt;builtin&gt;: recipe for target 'preadv02' failed
make[4]: *** [preadv02] Error 1
make[4]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls/preadv'
../../../include/mk/generic_trunk_target.inc:93: recipe for target 'all' failed
make[3]: *** [all] Error 2
make[3]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel/syscalls'
../../include/mk/generic_trunk_target.inc:93: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases/kernel'
../include/mk/generic_trunk_target.inc:93: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/usr/local/google/home/sspatil/dev/ssd2/ltp/testcases'
Makefile:111: recipe for target 'testcases-all' failed
make: *** [testcases-all] Error 2
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">

Kind regards,
Petr
</pre>
    </blockquote>
  </body>
</html>
Petr Vorel April 21, 2019, 10:10 p.m. UTC | #15
Hi Sandeep, Zhengwang,

> > I don't know why autotools fails preadv and pwritev detection with AC_CHECK_FUNCS.
> > I considered it as problem of my setup, but maybe it's an autotools bug.

> I also encountered this issue, but I temporarily walked around it by
> applying the following patch.

> ==================

> $ git diff testcases/
> diff --git a/testcases/commands/ldd/datafiles/Makefile
> b/testcases/commands/ldd/datafiles/Makefile
> index d8bcf5c..74fbe50 100644
> --- a/testcases/commands/ldd/datafiles/Makefile
> +++ b/testcases/commands/ldd/datafiles/Makefile
> @@ -30,7 +30,7 @@ CLEAN_TARGETS         += *.obj $(LDD_SO_FILES)
>         $(CC) $(CFLAGS) -shared -o $@ $^

>  lddfile.out: main.o $(LDD_SO_FILES)
> -       $(CC) $(CFLAGS) -O -o $@ $?
> +       $(CC) $(CFLAGS) $(LDFLAGS) -O -o $@ $?
What is this change for?

>  INSTALL_DIR            := testcases/data/ldd01

> diff --git a/testcases/kernel/syscalls/Makefile
> b/testcases/kernel/syscalls/Makefile
> index 45a00cf..27c2e7a 100644
> --- a/testcases/kernel/syscalls/Makefile
> +++ b/testcases/kernel/syscalls/Makefile
> @@ -43,6 +43,8 @@ FILTER_OUT_DIRS       += \
>         sched_getaffinity sched_setaffinity sendmsg setgroups setns sighold
> \
>         sigrelse sigsuspend sigtimedwait sigwait sigwaitinfo stime \
>         setdomainname sethostname symlinkat ulimit ustat vfork vhangup
> vmsplice
> +
> +FILTER_OUT_DIRS += preadv pwritev
Yes, that fixes build. But manually disabling features in config.h enables these
tests to be build.

Kind regards,
Petr
阮正旺 April 23, 2019, 5:28 p.m. UTC | #16
Hi Petr,


-------- Original Message --------
From: Petr Vorel
Sent: Mon, 22 Apr 2019 00:10:30 +0200
To: Zhengwang Ruan
Cc: Sandeep Patil, Ltp, Steve Muckle
Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable 
__ANDROID__ definition for Android build
> Hi Sandeep, Zhengwang,
>
>>> I don't know why autotools fails preadv and pwritev detection with AC_CHECK_FUNCS.
>>> I considered it as problem of my setup, but maybe it's an autotools bug.
>> I also encountered this issue, but I temporarily walked around it by
>> applying the following patch.
>> ==================
>> $ git diff testcases/
>> diff --git a/testcases/commands/ldd/datafiles/Makefile
>> b/testcases/commands/ldd/datafiles/Makefile
>> index d8bcf5c..74fbe50 100644
>> --- a/testcases/commands/ldd/datafiles/Makefile
>> +++ b/testcases/commands/ldd/datafiles/Makefile
>> @@ -30,7 +30,7 @@ CLEAN_TARGETS         += *.obj $(LDD_SO_FILES)
>>          $(CC) $(CFLAGS) -shared -o $@ $^
>>   lddfile.out: main.o $(LDD_SO_FILES)
>> -       $(CC) $(CFLAGS) -O -o $@ $?
>> +       $(CC) $(CFLAGS) $(LDFLAGS) -O -o $@ $?
> What is this change for?

This is a really long story. In my build, I need to use '-nostdlib  
/ndk/path/to/crtend_android.o /ndk/path/to/crtbegin_dynamic.o' as linker 
arguments to cross-compile, and I have to put these arguments into 
LDFLAGS since there were other errors occurred on linking *.o to 
executable if I put them into CFLAGS.

Right here, lddfile.out is an executable and obviously needed to be 
linked, therefore LDFLAGS must be required in my case.


Regards,

Zhengwang


>
>>   INSTALL_DIR            := testcases/data/ldd01
>> diff --git a/testcases/kernel/syscalls/Makefile
>> b/testcases/kernel/syscalls/Makefile
>> index 45a00cf..27c2e7a 100644
>> --- a/testcases/kernel/syscalls/Makefile
>> +++ b/testcases/kernel/syscalls/Makefile
>> @@ -43,6 +43,8 @@ FILTER_OUT_DIRS       += \
>>          sched_getaffinity sched_setaffinity sendmsg setgroups setns sighold
>> \
>>          sigrelse sigsuspend sigtimedwait sigwait sigwaitinfo stime \
>>          setdomainname sethostname symlinkat ulimit ustat vfork vhangup
>> vmsplice
>> +
>> +FILTER_OUT_DIRS += preadv pwritev
> Yes, that fixes build. But manually disabling features in config.h enables these
> tests to be build.
>
> Kind regards,
> Petr
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body smarttemplateinserted="true">
    <div id="smartTemplate4-template">
      <p>Hi Petr,<br>
      </p>
    </div>
    <br>
    <div id="smartTemplate4-quoteHeader">-------- Original Message --------<br>
      From: Petr Vorel<br>
      Sent: Mon, 22 Apr 2019 00:10:30 +0200<br>
      To: Zhengwang Ruan<br>
      Cc: Sandeep Patil, Ltp, Steve Muckle<br>
      Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable
      __ANDROID__ definition for Android build<br>
    </div>
    <blockquote type="cite" cite="mid:20190421221030.GA11307@x230">
      <pre class="moz-quote-pre" wrap="">Hi Sandeep, Zhengwang,

</pre>
      <blockquote type="cite">
        <blockquote type="cite">
          <pre class="moz-quote-pre" wrap="">I don't know why autotools fails preadv and pwritev detection with AC_CHECK_FUNCS.
I considered it as problem of my setup, but maybe it's an autotools bug.
</pre>
        </blockquote>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">I also encountered this issue, but I temporarily walked around it by
applying the following patch.
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">==================
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">$ git diff testcases/
diff --git a/testcases/commands/ldd/datafiles/Makefile
b/testcases/commands/ldd/datafiles/Makefile
index d8bcf5c..74fbe50 100644
--- a/testcases/commands/ldd/datafiles/Makefile
+++ b/testcases/commands/ldd/datafiles/Makefile
@@ -30,7 +30,7 @@ CLEAN_TARGETS         += *.obj $(LDD_SO_FILES)
        $(CC) $(CFLAGS) -shared -o $@ $^
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap=""> lddfile.out: main.o $(LDD_SO_FILES)
-       $(CC) $(CFLAGS) -O -o $@ $?
+       $(CC) $(CFLAGS) $(LDFLAGS) -O -o $@ $?
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">What is this change for?</pre>
    </blockquote>
    <p>This is a really long story. In my build, I need to use
      '-nostdlib  /ndk/path/to/crtend_android.o
      /ndk/path/to/crtbegin_dynamic.o' as linker arguments to
      cross-compile, and I have to put these arguments into LDFLAGS
      since there were other errors occurred on linking *.o to
      executable if I put them into CFLAGS.  <br>
    </p>
    <p>Right here, lddfile.out is an executable and obviously needed to
      be linked, therefore LDFLAGS must be required in my case.  <br>
    </p>
    <p><br>
    </p>
    <p>Regards,</p>
    <p>Zhengwang<br>
    </p>
    <p><br>
    </p>
    <blockquote type="cite" cite="mid:20190421221030.GA11307@x230">
      <pre class="moz-quote-pre" wrap="">

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap=""> INSTALL_DIR            := testcases/data/ldd01
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">diff --git a/testcases/kernel/syscalls/Makefile
b/testcases/kernel/syscalls/Makefile
index 45a00cf..27c2e7a 100644
--- a/testcases/kernel/syscalls/Makefile
+++ b/testcases/kernel/syscalls/Makefile
@@ -43,6 +43,8 @@ FILTER_OUT_DIRS       += \
        sched_getaffinity sched_setaffinity sendmsg setgroups setns sighold
\
        sigrelse sigsuspend sigtimedwait sigwait sigwaitinfo stime \
        setdomainname sethostname symlinkat ulimit ustat vfork vhangup
vmsplice
+
+FILTER_OUT_DIRS += preadv pwritev
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">Yes, that fixes build. But manually disabling features in config.h enables these
tests to be build.

Kind regards,
Petr
</pre>
    </blockquote>
  </body>
</html>
Petr Vorel April 23, 2019, 8:38 p.m. UTC | #17
Hi Zhengwang,


> -------- Original Message --------
> From: Petr Vorel
> Sent: Mon, 22 Apr 2019 00:10:30 +0200
> To: Zhengwang Ruan
> Cc: Sandeep Patil, Ltp, Steve Muckle
> Subject: Re: [LTP] 回复:[PATCH v1] include/mk/env_post.mk : enable
> __ANDROID__ definition for Android build
> > Hi Sandeep, Zhengwang,

> > > > I don't know why autotools fails preadv and pwritev detection with AC_CHECK_FUNCS.
> > > > I considered it as problem of my setup, but maybe it's an autotools bug.
> > > I also encountered this issue, but I temporarily walked around it by
> > > applying the following patch.
> > > ==================
> > > $ git diff testcases/
> > > diff --git a/testcases/commands/ldd/datafiles/Makefile
> > > b/testcases/commands/ldd/datafiles/Makefile
> > > index d8bcf5c..74fbe50 100644
> > > --- a/testcases/commands/ldd/datafiles/Makefile
> > > +++ b/testcases/commands/ldd/datafiles/Makefile
> > > @@ -30,7 +30,7 @@ CLEAN_TARGETS         += *.obj $(LDD_SO_FILES)
> > >          $(CC) $(CFLAGS) -shared -o $@ $^
> > >   lddfile.out: main.o $(LDD_SO_FILES)
> > > -       $(CC) $(CFLAGS) -O -o $@ $?
> > > +       $(CC) $(CFLAGS) $(LDFLAGS) -O -o $@ $?
> > What is this change for?

> This is a really long story. In my build, I need to use '-nostdlib 
> /ndk/path/to/crtend_android.o /ndk/path/to/crtbegin_dynamic.o' as linker
> arguments to cross-compile, and I have to put these arguments into LDFLAGS
> since there were other errors occurred on linking *.o to executable if I put
> them into CFLAGS.

> Right here, lddfile.out is an executable and obviously needed to be linked,
> therefore LDFLAGS must be required in my case.

Thanks for info. Feel free to send a patch with a long description.

Back to the patch: I'm willing to merge it, just wait if any from Sandeep or
Steve (or any other android developer) will ack it.


Kind regards,
Petr
diff mbox series

Patch

diff --git a/include/mk/env_post.mk b/include/mk/env_post.mk
index 913bdf5..7953e0a 100644
--- a/include/mk/env_post.mk
+++ b/include/mk/env_post.mk
@@ -44,7 +44,7 @@  endif
 ifeq ($(ANDROID),1)
 # There are many undeclared functions, it's best not to accidentally overlook
 # them.
-CFLAGS    += -Werror-implicit-function-declaration
+CFLAGS    += -Werror-implicit-function-declaration -D__ANDROID__

 LDFLAGS    += -L$(top_builddir)/lib/android_libpthread
 LDFLAGS    += -L$(top_builddir)/lib/android_librt