On 14-12-24 04:11, John Reiser wrote:
I've tried to build the last release but have not resolved the place why it tries to link against the non-existing libc and how to fix that...

Here are some workarounds:

I'm trying to build valgrind (memcheck) for 32-bit programs on Android
running under 64-bit TermUX on 64-bit Android 14.  A fully-static 32-
bit program created under Linux on [old] RaspberryPi does run
under TermUX on my Samsung A9-Lite tablet with 3MB RAM!  All building
for valgrind was done on the tablet.

Starting with "git clone; ./aclocal; ./configure --prefix=...";
then in just a few minutes "make -j4" reaches
=====
$ gcc ... `m_coredump/coredump-elf.c
m_coredump/coredump-elf.c:152:4: error: typedef redefinition with different types ('struct Elf32_Nhdr' vs 'struct elf32_note')
   152 |    Elf32_Nhdr;
       |    ^
/data/data/com.termux/files/usr/include/linux/elf.h:380:3: note: previous definition is here
   380 | } Elf32_Nhdr;
       |   ^
m_coredump/coredump-elf.c:775:17: warning: variable 'name' set but not used [-Wunused-but-set-variable]
   775 |    const HChar* name;
       |                 ^
=====

My usr/include/elf.h from ndk-root version 27c does have a Elf32_Nhdr,
so I patch with
=====
diff --git a/coregrind/m_coredump/coredump-elf.c b/coregrind/m_coredump/ coredump-elf.c
index a4632d9e2..aa58e6f48 100644
--- a/coregrind/m_coredump/coredump-elf.c
+++ b/coregrind/m_coredump/coredump-elf.c
@@ -140,8 +140,8 @@ static void fill_phdr(ESZ(Phdr) *phdr, const NSegment *seg, UInt off, Bool write
     phdr->p_align = VKI_PAGE_SIZE;
  }

-#if defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \
-    || defined(VGPV_mips32_linux_android)
+#if 0 && ( defined(VGPV_arm_linux_android) || defined(VGPV_x86_linux_android) \
+    || defined(VGPV_mips32_linux_android))
  /* Android's libc doesn't provide a definition for this.  Hence: */
  typedef
     struct {
=====


If elf.h doesn't indicate that it has a Elf32_Nhdr then we could add a configure check for that. See https://bugs.kde.org/show_bug.cgi?id=339861. Do we need to keep backwards compatibility with the old systems that didn't have Elf32_Nhdr?

Building proceeds until
=====  (Note "-m32")
$ gcc -m64 ... -static ... -m32 -o vgpreload_core-arm-linux.so \
      vgpreload_core_arm_linux_so_preloaded.o
ld.lld: error: unable to find library -lc
=====
which I workaround by running "gcc -v ...", to get the command line,
then manually running the 'ld' without the "-lc".  So gcc adding
"-lc" was not necessary?


What is the full text of the line for linking vgpreload_core-arm-linux.so?

I don't know where -lc is coming from, maybe implicitly with lld and it needs -nostdlib.

Also I don't see how both -m32 and -m64 get added. In this case it seems harmless as the later -m32 will be taken.


More building until (in directory coregrind):
=====   (Note no "-m32")
$ gcc -m64 ... -static ... -o valgrind \
      valgrind-launcher-linux.o valgrind-m_debuglog.o
ld.lld: error: unable to find library -lc
=====

Next "dpkg --search libc.a" shows a nice-looking
    usr/opt/ndk-multilib/aarch64-linux-android/lib/libc.a
and manually adding that appears to succeed:
=====
$ cd /data/data/com.termux/files/home/valgrind/coregrind
$ ld -o valgrind  valgrind-launcher-linux.o valgrind-m_debuglog.o \

/data/data/com.termux/files/usr/opt/ndk-multilib/aarch64-linux-android/ lib/libc.a
$ readelf --all --wide valgrind >valgrind.readelfcd ..
    # 5744 lines; 10 Program headers; 29 Sections
# Header      Offset   VirtAddr  PhysAddr  Fsiz  Msiz Flg  Align
#  TLS       0x069870  0x271870  0x271870     8     8   R  0x8
=====

But a trial run fails:
=====
$ cd coregrind
$ ./valgrind
error: "./valgrind": executable's TLS segment is underaligned: \
alignment is 8 (skew 0), needs to be at least 64 for ARM64 Bionic
Aborted
$ echo $?
134   ## error 6 (134 - 128) ENXIO
$
=====

So now it's time to get the linker script from "ld --verbose ...",
then make TLS 64-byte aligned.   To be continued ...

Do the Google/Android folks have any Valgrind patches for these issues?

A+
Paul




_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to