Bug 339861 - Remove Elf32_Nhdr definition for Android
Summary: Remove Elf32_Nhdr definition for Android
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Android Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-10-10 23:39 UTC by dimitry
Modified: 2020-11-03 10:11 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Elf32_Nhdr.patch (664 bytes, patch)
2014-10-10 23:40 UTC, dimitry
Details
open Elf32_Nhdr definition only for Android API level less than 21 (635 bytes, patch)
2015-08-24 18:39 UTC, Chiu-Hsiang Hsu
Details
Variant: only disable this on __clang__ (1.15 KB, patch)
2019-05-30 01:38 UTC, Benoit Jacob
Details

Note You need to log in before you can comment on or make changes to this bug.
Description dimitry 2014-10-10 23:39:10 UTC
Android header files define both Elf32_Nhdr and Elf64_Nhdr. The attached patch removes redefinition of the struct

Reproducible: Always
Comment 1 dimitry 2014-10-10 23:40:01 UTC
Created attachment 89085 [details]
Elf32_Nhdr.patch
Comment 2 Chiu-Hsiang Hsu 2015-08-21 08:24:34 UTC
I still encounter this problem. (patch works though)
Comment 3 Julian Seward 2015-08-21 13:24:28 UTC
(In reply to Chiu-Hsiang Hsu from comment #2)
> I still encounter this problem. 

On what Android version?
Comment 4 Chiu-Hsiang Hsu 2015-08-21 13:38:21 UTC
(In reply to Julian Seward from comment #3)
> (In reply to Chiu-Hsiang Hsu from comment #2)
> > I still encounter this problem. 
> 
> On what Android version?

compiling Valgrind with android-ndk-r10e-linux-x86_64.bin
platform : android-21

----

full compiling command :

$ wget http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin
$ chmod u+x android-ndk-r10e-linux-x86_64.bin
$ ./android-ndk-r10e-linux-x86_64.bin
$ export NDKROOT=/path/to/android-ndk-r10e  # modify your path
$ svn co svn://svn.valgrind.org/valgrind/trunk valgrind
$ cd valgrind
$ export AR=$NDKROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar
$ export LD=$NDKROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld
$ export CC=$NDKROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
$ ./autogen.sh
$ CPPFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm" \
      CFLAGS="--sysroot=$NDKROOT/platforms/android-21/arch-arm" \
      ./configure --prefix=/data/local/Inst \
      --host=armv7-unknown-linux --target=armv7-unknown-linux \
      --with-tmpdir=/sdcard
$ make -j8
Comment 5 Julian Seward 2015-08-21 14:17:29 UTC
If this is to be committed, it needs some kind of conditionalisation.
For example, the patch causes the build to fail when using android-ndk-r6
and platform android-3:

m_coredump/coredump-elf.c:158: error: 'Elf32_Nhdr' undeclared (first use in this function)
Comment 6 Chiu-Hsiang Hsu 2015-08-24 18:39:36 UTC
Created attachment 94205 [details]
open Elf32_Nhdr definition only for Android API level less than 21

I try to keep the definition only for Android API level less than 21.
Tested with android-ndk-r10e for platform android-3, android-19, android-21.
Comment 7 Elliott Hughes 2017-05-12 23:00:52 UTC
when NDK r15 ships, the unified headers will be the default, so all API levels will have this defined and dimitry's patch (that just removes this) will work, but chh's conditional patch will stop working then (even though it works with <= r14).

in the AOSP tree we're basically carrying dimitry's patch, but it might make more sense for upstream to wait for r15 to ship (hopefully june/july).
Comment 8 Benoit Jacob 2019-05-30 01:38:41 UTC
Created attachment 120387 [details]
Variant: only disable this on __clang__

Here is another patch that preserves the existing behavior unless __clang__ is defined.  Building with clang only became the default in NDK r13, in late 2016.
Comment 9 Maxim P. Dementiev 2020-11-03 10:11:24 UTC
I have got the same problem

> m_coredump/coredump-elf.c:149:4: error: typedef redefinition with different types ('struct Elf32_Nhdr' vs 'struct elf32_note')
> /home/xxx/Android/android-ndk-r21/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/linux/elf.h:370:3: note: previous definition is here

On my Gentoo:

> Linux maxmsi 5.7.19-gentoo #1 SMP Thu Sep 3 23:53:16 CEST 2020 x86_64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz GenuineIntel GNU/Linux

Building on master:

> commit 2471e0521da06200bd9d553b4d17750af2852bb0
> Author: Julian Seward <jseward@acm.org>
> Date:   Fri Oct 30 17:34:14 2020 +0100
> 
>    arm64 front end: mark a couple of vector load/store insns as "verbose".

Solved by commenting Elf32_Nhdr typedef in coregrind/m_coredump/coredump-elf.c

The funny comment stays since:

> 0ef7dc3c2f coregrind/m_coredump/coredump-elf.c (Julian Seward       2011-07-12 07:14:47 +0000 142) /* Android's libc doesn't provide a definition for this.  Hence: */