1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-21 06:55:39 +00:00

Update Android port

* Makefile.in (extraclean): Clean in exec as well.
* configure.ac: Fix detection of absolute srcdir.  Also, pass
CFLAGS.
* exec/Makefile.in: (.c.o): Add -I. so config.h can be
found.:(.s.o): Don't create m4 temporary in srcdir.
* exec/config-mips.m4.in (DADDI2, DADDI3): New macros.  Define
to substitute if as cannot assemble daddi.
* exec/configure.ac (user_h): Look for user.h in asm/ as well.
Use new user.h.  Also look in ptrace.h on arm systems.  Check if
as supports daddi on mips64.
* exec/exec.c (check_interpreter): Fix char signedness bug.
* exec/loader-mips64el.s (__start): Use DADDI2 and DADDI3 for
two- and 3-operand daddi.
* exec/mipsel-user.h: Don't include sgidefs.h.
* java/INSTALL: Document that m4 is now required.
* src/android.c (android_rewrite_spawn_argv): Add missing NULL.
This commit is contained in:
Po Lu 2023-05-01 11:28:22 +08:00
parent a8f9a4d2d9
commit ddc16de869
10 changed files with 114 additions and 49 deletions

View File

@ -1101,6 +1101,8 @@ extraclean: maintainer-clean
-[ "${srcdir}" = "." ] || \
find ${srcdir} '(' -name '*~' -o -name '#*' ')' ${FIND_DELETE}
-find . '(' -name '*~' -o -name '#*' ')' ${FIND_DELETE}
-rm -f ${srcdir}/exec/config-tmp-* ${srcdir}/exec/aclocal.m4 \
${srcdir}/src/config.in ${srcdir}/exec/configure
# The src subdir knows how to do the right thing
# even when the build directory and source dir are different.

View File

@ -179,7 +179,6 @@ AS_IF([test "$XCONFIGURE" = "android"],[
# At the same time, configure libexec with the build directory
# set to `exec'.
AS_MKDIR_P([exec])
AC_MSG_NOTICE([configuring in `exec'])
# Enter exec and configure it, using the C compiler as both the
# assembler and the linker. Determine the absolute name of the
@ -187,18 +186,21 @@ AS_IF([test "$XCONFIGURE" = "android"],[
# N.B. that the linker is actually cc, so pass -nostdlib, lest
# the crt be linked in. Likewise for as.
AS_CASE([$ac_srcdir], [.], [emacs_srcdir=`pwd`],
[[[\\/]* | ?:[\\/]*]], [emacs_srcdir=$ac_srcdir],
[*], [emacs_srcdir=`pwd`/$ac_srcdir])
AS_CASE([$srcdir], [.], [emacs_srcdir=`pwd`],
[[[\\/]* | ?:[\\/]*]], [emacs_srcdir=$srcdir],
[*], [emacs_srcdir=`pwd`/$srcdir])
AC_MSG_NOTICE([configuring in `exec'])
OLDCWD=`pwd`
cd exec
$CONFIG_SHELL $emacs_srcdir/exec/configure \
--host=$host CC=$CC LD=$CC AS=$CC \
AR=$AR ASFLAGS=-c
$CONFIG_SHELL $emacs_srcdir/exec/configure \
--host=$host "CC=$CC" "LD=$CC" "AS=$CC" \
"AR=$AR" "CFLAGS=$CFLAGS"
emacs_val=$?
cd $OLDCWD
AS_IF([test "$?" != "0"],
AS_IF([test "$emacs_val" != "0"],
[AC_MSG_ERROR([failed to configure in `exec'])])
])

View File

@ -81,10 +81,10 @@ Makefile: config.status Makefile.in
.SUFFIXES: .c .s
.c.o:
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEPFLAGS) -I$(srcdir) $< -o $@
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEPFLAGS) -I$(srcdir) -I. $< -o $@
.s.o:
$(M4) $< > $<.s
$(AS) $(ASFLAGS) $<.s -o $@
$(M4) $< > $(notdir $<).s
$(AS) $(ASFLAGS) $(notdir $<).s -o $@
# Set up dependencies for config-mips.m4.

View File

@ -34,3 +34,9 @@ define(`SYSCALL', `ifelse(`@MIPS_N32@',`yes',` move $a4, $1
sw $4, 28($sp)')')
define(`RESTORE', `ifelse(`@MIPS_N32@',`yes',` nop',` addi $sp, 32')')
dnl For mips64. Some assemblers don't want to assemble `daddi'.
define(`DADDI2', `ifelse(`@DADDI_BROKEN@',`yes',` li $at, $2
dadd $1, $1, $at',` daddi $1, $2')')
define(`DADDI3', `ifelse(`@DADDI_BROKEN@',`yes',` li $at, $3
dadd $1, $2, $at',` daddi $1, $2, $3')')

View File

@ -96,6 +96,13 @@ AH_TEMPLATE([CLONE3_SYSCALL], [Define to number of the `clone3' system call.])
AC_CANONICAL_HOST
# Check whether or not sys/user exists. If it doesn't, try
# asm/user.h, and croak if that doesn't exist either.
AS_CASE([$host], [*mips*], [], [*],
[AC_CHECK_HEADER([sys/user.h], [user_h="<sys/user.h>"],
[AC_CHECK_HEADER([asm/user.h], [user_h="<asm/user.h>"],
[AC_MSG_ERROR([Can not find working user.h])])])])
# Look for required tools.
AC_ARG_VAR([M4], [`m4' preprocessor command.])
@ -187,11 +194,12 @@ AS_IF([test "x$exec_cv_mips_nabi" != "xno"],
exec_loader=
is_mips=
OBJS="exec.o trace.o"
DADDI_BROKEN=no
AS_CASE([$host], [x86_64-*linux*],
[AC_CHECK_MEMBER([struct user_regs_struct.rdi],
[AC_DEFINE([SYSCALL_HEADER], [<asm/unistd.h>])
AC_DEFINE([USER_HEADER], [<sys/user.h>])
AC_DEFINE_UNQUOTED([USER_HEADER], [$user_h])
AC_DEFINE([USER_REGS_STRUCT], [struct user_regs_struct])
AC_DEFINE([SYSCALL_NUM_REG], [orig_rax])
AC_DEFINE([SYSCALL_RET_REG], [rax])
@ -213,11 +221,11 @@ AS_CASE([$host], [x86_64-*linux*],
exec_loader=loader-x86_64.s],
[AC_MSG_ERROR([Missing `rdi' in user_regs_struct])],
[[
#include <sys/user.h>
#include $user_h
]])], [i[[34567]]86-*linux*],
[AC_CHECK_MEMBER([struct user_regs_struct.edi],
[AC_DEFINE([SYSCALL_HEADER], [<asm/unistd.h>])
AC_DEFINE([USER_HEADER], [<sys/user.h>])
AC_DEFINE_UNQUOTED([USER_HEADER], [$user_h])
AC_DEFINE([USER_REGS_STRUCT], [struct user_regs_struct])
AC_DEFINE([SYSCALL_NUM_REG], [orig_eax])
AC_DEFINE([SYSCALL_RET_REG], [eax])
@ -237,11 +245,11 @@ AS_CASE([$host], [x86_64-*linux*],
exec_loader=loader-x86.s],
[AC_MSG_ERROR([Missing `edi' in user_regs_struct])],
[[
#include <sys/user.h>
#include $user_h
]])], [aarch64-*linux*],
[AC_CHECK_MEMBER([struct user_regs_struct.sp],
[AC_DEFINE([SYSCALL_HEADER], [<asm/unistd.h>])
AC_DEFINE([USER_HEADER], [<sys/user.h>])
AC_DEFINE_UNQUOTED([USER_HEADER], [$user_h])
AC_DEFINE([USER_REGS_STRUCT], [struct user_regs_struct])
AC_DEFINE([SYSCALL_NUM_REG], [[regs[8]]])
AC_DEFINE([SYSCALL_RET_REG], [[regs[0]]])
@ -263,11 +271,11 @@ AS_CASE([$host], [x86_64-*linux*],
exec_loader=loader-aarch64.s],
[AC_MSG_ERROR([Missing `sp' in user_regs_struct])],
[[
#include <sys/user.h>
#include $user_h
]])], [arm*linux*eabi* | armv7*linux*],
[AC_CHECK_MEMBER([struct user_regs.uregs],
[AC_DEFINE([SYSCALL_HEADER], [<asm/unistd.h>])
AC_DEFINE([USER_HEADER], [<sys/user.h>])
AC_DEFINE_UNQUOTED([USER_HEADER], [$user_h])
AC_DEFINE([USER_REGS_STRUCT], [struct user_regs])
AC_DEFINE([SYSCALL_NUM_REG], [[uregs[7]]])
AC_DEFINE([SYSCALL_RET_REG], [[uregs[0]]])
@ -283,9 +291,30 @@ AS_CASE([$host], [x86_64-*linux*],
exec_CHECK_LINUX_CLONE3
LOADERFLAGS="$LOADERFLAGS $LDPREFIX-Ttext=0x20000000"
exec_loader=loader-armeabi.s],
[AC_MSG_ERROR([Missing `uregs' in user_regs_struct])],
[AC_CHECK_MEMBER([struct pt_regs.uregs],
[AC_DEFINE([SYSCALL_HEADER], [<asm/unistd.h>])
AC_DEFINE_UNQUOTED([USER_HEADER], [<asm/ptrace.h>])
AC_DEFINE([USER_REGS_STRUCT], [struct pt_regs])
AC_DEFINE([SYSCALL_NUM_REG], [[uregs[7]]])
AC_DEFINE([SYSCALL_RET_REG], [[uregs[0]]])
AC_DEFINE([SYSCALL_ARG_REG], [[uregs[0]]])
AC_DEFINE([SYSCALL_ARG1_REG], [[uregs[1]]])
AC_DEFINE([STACK_POINTER], [[uregs[13]]])
AC_DEFINE([EXEC_SYSCALL], [__NR_execve])
AC_DEFINE([USER_WORD], [uintptr_t])
AC_DEFINE([EXECUTABLE_BASE], [0x0f000000])
AC_DEFINE([INTERPRETER_BASE], [0x1f000000])
AC_DEFINE([STACK_GROWS_DOWNWARDS], [1])
AC_DEFINE([CLONE_SYSCALL], [__NR_clone])
exec_CHECK_LINUX_CLONE3
LOADERFLAGS="$LOADERFLAGS $LDPREFIX-Ttext=0x20000000"
exec_loader=loader-armeabi.s],
[AC_MSG_ERROR([Missing `uregs' in user_regs_struct or pt_regs])],
[[
#include <asm/ptrace.h>
]])],
[[
#include <sys/user.h>
#include $user_h
]])], [mipsel*linux*],
[AC_DEFINE([SYSCALL_HEADER], [<asm/unistd.h>])
AC_DEFINE([USER_HEADER], ["mipsel-user.h"])
@ -325,6 +354,27 @@ AS_CASE([$host], [x86_64-*linux*],
AC_DEFINE([INTERPRETER_BASE], [0x3f00000000])
AC_DEFINE([STACK_GROWS_DOWNWARDS], [1])
AC_DEFINE([CLONE_SYSCALL], [__NR_clone])
AC_CACHE_CHECK([whether as understands `daddi'],
[exec_cv_as_daddi],
[exec_cv_as_daddi=no
cat <<_ACEOF >conftest.s
.section text
.global __start
__start:
li $t0, 0
li $t1, 0
daddi $t0, $t1, 1
daddi $t0, $t1, -1
daddi $t0, -1
daddi $t0, 1
_ACEOF
$AS $ASFLAGS conftest.s -o conftest.$OBJEXT \
>&AS_MESSAGE_LOG_FD 2>&1 \
&& exec_cv_as_daddi=yes
rm -f conftest.s conftest.$OBJEXT])
AS_IF([test "x$exec_cv_as_daddi" != "xyes"],
[DADDI_BROKEN=yes])
exec_CHECK_LINUX_CLONE3
exec_CHECK_MIPS_NABI
LOADERFLAGS="$LOADERFLAGS $LDPREFIX-Ttext=0x3e00000000"
@ -332,6 +382,8 @@ AS_CASE([$host], [x86_64-*linux*],
exec_loader=loader-mips64el.s], [*],
[AC_MSG_ERROR([Please port libexec to $host])])
AC_SUBST([DADDI_BROKEN])
MIPS_N32=$exec_cv_mips_nabi
AC_ARG_VAR([LOADERFLAGS], [Flags used to link the loader.])

View File

@ -95,7 +95,7 @@ check_interpreter (const char *name, int fd, const char **extra)
/* Strip leading whitespace. */
start = buffer;
while (*start && *start < 128 && isspace (*start))
while (*start && ((unsigned char) *start) < 128 && isspace (*start))
++start;
/* Look for a newline character. */

View File

@ -15,7 +15,10 @@
# You should have received a copy of the GNU General Public License
# along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
include(`config-mips.m4')
.set noreorder # delay slots managed by hand
.set noat # no assembler macros
.section .text
.global __start
__start:
@ -24,8 +27,8 @@ dnl dla $a0, .timespec # rqtp
dnl li $a1, 0 # rmtp
dnl syscall # syscall
ld $s2, ($sp) # original stack pointer
daddi $s0, $sp, 16 # start of load area
daddi $sp, -16 # primary fd, secondary fd
DADDI3( $s0, $sp, 16) # start of load area
DADDI2( $sp, -16) # primary fd, secondary fd
li $t0, -1 # secondary fd
sd $t0, 8($sp) # initialize secondary fd
.next_action:
@ -33,7 +36,7 @@ dnl syscall # syscall
andi $t0, $s1, 15 # t0 = action number & 15
beqz $t0, .open_file # open file?
nop # delay slot
daddi $t0, -3 # t0 -= 3
DADDI2( $t0, -3) # t0 -= 3
beqz $t0, .rest_of_exec # jump to code
nop # delay slot
li $t1, 1
@ -76,30 +79,30 @@ dnl syscall # syscall
bne $t2, $zero, .fillb # fill bytes
nop # delay slot
sd $zero, ($t1) # zero doubleword
daddi $t1, 8 # next doubleword
DADDI2( $t1, 8) # next doubleword
sd $zero, ($t1) # zero doubleword
daddi $t1, 8 # next doubleword
DADDI2( $t1, 8) # next doubleword
sd $zero, ($t1) # zero doubleword
daddi $t1, 8 # next doubleword
DADDI2( $t1, 8) # next doubleword
sd $zero, ($t1) # zero doubleword
daddi $t1, 8 # next doubleword
DADDI2( $t1, 8) # next doubleword
sd $zero, ($t1) # zero doubleword
daddi $t1, 8 # next doubleword
DADDI2( $t1, 8) # next doubleword
sd $zero, ($t1) # zero doubleword
daddi $t1, 8 # next doubleword
DADDI2( $t1, 8) # next doubleword
sd $zero, ($t1) # zero doubleword
daddi $t1, 8 # next doubleword
DADDI2( $t1, 8) # next doubleword
sd $zero, ($t1) # zero doubleword
daddi $t1, 8 # next doubleword
DADDI2( $t1, 8) # next doubleword
j .filld # fill either doubleword or byte
nop # delay slot
.fillb:
beq $t0, $t1, .continue # already finished?
nop # delay slot
sb $zero, ($t1) # clear byte
daddi $t1, $t1, 1 # t1++
DADDI2( $t1, 1) # t1++
.continue:
daddi $s0, $s0, 56 # s0 = next action
DADDI2( $s0, 56) # s0 = next action
j .next_action # next action
nop # delay slot
.do_mmap_anon:
@ -113,26 +116,26 @@ dnl syscall # syscall
nop # branch delay slot
.open_file:
li $v0, 5002 # SYS_open
daddi $a0, $s0, 8 # start of name
DADDI3( $a0, $s0, 8) # start of name
move $a1, $zero # flags = O_RDONLY
move $a2, $zero # mode = 0
syscall # syscall
bne $a3, $zero, .perror # perror
nop # delay slot
daddi $s0, $s0, 8 # start of string
DADDI2( $s0, 8) # start of string
.nextc:
lb $t0, ($s0) # load byte
daddi $s0, $s0, 1 # s0++
DADDI2( $s0, 1) # s0++
bne $t0, $zero, .nextc # next character?
nop # delay slot
daddi $s0, $s0, 7 # adjust for round
DADDI2( $s0, 7) # adjust for round
li $t2, -8 # t2 = -8
and $s0, $s0, $t2 # mask for round
andi $t0, $s1, 16 # t1 = s1 & 16
move $t1, $sp # address of primary fd
beqz $t0, .primary # primary fd?
nop # delay slot
daddi $t1, $t1, 8 # address of secondary fd
DADDI2( $t1, 8) # address of secondary fd
.primary:
sd $v0, ($t1) # store fd
j .next_action # next action
@ -145,11 +148,11 @@ dnl syscall # syscall
move $s1, $s2 # original SP
ld $t0, ($s1) # argc
dsll $t0, $t0, 3 # argc *= 3
daddi $t0, $t0, 16 # argc += 16
DADDI2( $t0, 16) # argc += 16
dadd $s1, $s1, $t0 # s1 = start of envp
.skipenv:
ld $t0, ($s1) # t0 = *s1
daddi $s1, $s1, 8 # s1++
DADDI2( $s1, 8) # s1++
bne $t0, $zero, .skipenv # skip again
nop # delay slot
dla $t3, .auxvtab # address of auxv table
@ -170,7 +173,7 @@ dnl syscall # syscall
ld $t2, ($t2) # t2 = *t2
sd $t2, 8($s1) # set auxv value
.next:
daddi $s1, $s1, 16 # next auxv
DADDI2( $s1, 16) # next auxv
j .one_auxv # next auxv
nop # delay slot
.finish:

View File

@ -22,7 +22,6 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#ifndef _MIPSEL_USER_H_
#define _MIPSEL_USER_H_
#include <sgidefs.h>
#include <sys/user.h>
#ifndef ELF_NGREG

View File

@ -22,10 +22,11 @@ your freedom's sake, you should use the Android SDK provided by the
Debian project.
In addition to the Android SDK and Android NDK, Emacs also requires
the Java compiler from OpenJDK 1.7.0 to be installed on your system.
Building on GNU systems is all that is officially supported. We are
told that Mac OS works too, and other Unix systems will likely work
as well, but MS Windows and Cygwin will not.
the Java compiler from OpenJDK 1.7.0 to be installed on your system,
along with a working `m4' macro processor. Building on GNU systems is
all that is officially supported. We are told that Mac OS works too,
and other Unix systems will likely work as well, but MS Windows and
Cygwin will not.
Once all of those tools are obtained, you may invoke the `configure'
script like so:

View File

@ -6584,8 +6584,8 @@ android_rewrite_spawn_argv (const char ***argv)
new_args[0] = exec1_name;
new_args[1] = loader_name;
/* And insert the rest. */
for (i = 0; i < nargs; ++i)
/* And insert the rest, including the trailing NULL. */
for (i = 0; i < nargs + 1; ++i)
new_args[i + 2] = (*argv)[i];
/* Replace argv. */