[ARM/FDPIC,1/4] linux-user: ARM-FDPIC: Add configure option to support loading of FDPIC binaries

Message ID 20180406151752.10854-2-christophe.lyon@st.com
State New
Headers show
Series
  • FDPIC ABI for ARM
Related show

Commit Message

Christophe Lyon April 6, 2018, 3:17 p.m.
Adds --enable-fdpic and --disable-fdpic configure options.  This
feature is disabled by default, that's why it is not described in the
"Optional features" help section (which are enabled by default if
possible).

FDPIC ELF objects are identified with e_ident[EI_OSABI] ==
ELFOSABI_ARM_FDPIC.

Co-Authored-By: Mickaël Guêné <mickael.guene@st.com>
Signed-off-by: Christophe Lyon <christophe.lyon@st.com>


-- 
2.6.3

Comments

Peter Maydell April 13, 2018, 3:04 p.m. | #1
On 6 April 2018 at 16:17, Christophe Lyon <christophe.lyon@st.com> wrote:
> Adds --enable-fdpic and --disable-fdpic configure options.  This

> feature is disabled by default, that's why it is not described in the

> "Optional features" help section (which are enabled by default if

> possible).

>

> FDPIC ELF objects are identified with e_ident[EI_OSABI] ==

> ELFOSABI_ARM_FDPIC.


If we can identify these ELF objects by looking in the ELF header,
why would we want to make this all a configure option that's
disabled by default?

I think we should just have support for these binaries enabled
always. Otherwise it will bitrot because nobody compiles it.

thanks
-- PMM
Christophe Lyon April 16, 2018, 7:57 a.m. | #2
On 13/04/2018 17:04, Peter Maydell wrote:
> On 6 April 2018 at 16:17, Christophe Lyon <christophe.lyon@st.com> wrote:

>> Adds --enable-fdpic and --disable-fdpic configure options.  This

>> feature is disabled by default, that's why it is not described in the

>> "Optional features" help section (which are enabled by default if

>> possible).

>>

>> FDPIC ELF objects are identified with e_ident[EI_OSABI] ==

>> ELFOSABI_ARM_FDPIC.

> 

> If we can identify these ELF objects by looking in the ELF header,

> why would we want to make this all a configure option that's

> disabled by default?

> 

> I think we should just have support for these binaries enabled

> always. Otherwise it will bitrot because nobody compiles it.

> 

We are relying on a pre-existing CONFIG_USE_FDPIC, which is currently
never defined. This was introduced by commit 1af02e83 back in 2011,
and indeed if you try to build QEMU with CONFIG_USE_FDPIC, the build fails because elf_is_fdpic() is not defined.

We tried to conform to this existing support, but maybe it's already bit-rotten?
Do you suggest removing CONFIG_USE_FDPIC?

Thanks



> thanks

> -- PMM

> .

>
Peter Maydell April 16, 2018, 9:19 a.m. | #3
On 16 April 2018 at 08:57, Christophe Lyon <christophe.lyon@st.com> wrote:
> On 13/04/2018 17:04, Peter Maydell wrote:

>> I think we should just have support for these binaries enabled

>> always. Otherwise it will bitrot because nobody compiles it.

>>

> We are relying on a pre-existing CONFIG_USE_FDPIC, which is currently

> never defined. This was introduced by commit 1af02e83 back in 2011,

> and indeed if you try to build QEMU with CONFIG_USE_FDPIC, the build fails

> because elf_is_fdpic() is not defined.


This looks like an excellent demonstration of why we shouldn't
hide this feature behind a defaults-to-off #define :-)

> Do you suggest removing CONFIG_USE_FDPIC?


Yes. Given how old the existing disabled FDPIC code is, I would also
suggest you carefully review any of it that you're using...

thanks
-- PMM

Patch

diff --git a/configure b/configure
index 4d0e92c..af4c14b 100755
--- a/configure
+++ b/configure
@@ -451,6 +451,7 @@  jemalloc="no"
 replication="yes"
 vxhs=""
 libxml2=""
+fdpic="no"
 
 supported_cpu="no"
 supported_os="no"
@@ -1374,6 +1375,10 @@  for opt do
   ;;
   --disable-git-update) git_update=no
   ;;
+  --disable-fdpic) fdpic="no"
+  ;;
+  --enable-fdpic) fdpic="yes"
+  ;;
   *)
       echo "ERROR: unknown option $opt"
       echo "Try '$0 --help' for more information"
@@ -1544,6 +1549,8 @@  Advanced options (experts only):
                            xen pv domain builder
   --enable-debug-stack-usage
                            track the maximum stack usage of stacks created by qemu_alloc_stack
+  --disable-fdpic          disable loading of FDPIC binary (default)
+  --enable-fdpic           enable loading of FDPIC binary
 
 Optional features, enabled with --enable-FEATURE and
 disabled with --disable-FEATURE, default is enabled if available:
@@ -7085,6 +7092,9 @@  fi
 
 echo "LDFLAGS+=$ldflags" >> $config_target_mak
 echo "QEMU_CFLAGS+=$cflags" >> $config_target_mak
+if [ "$fdpic" = "yes" ]; then
+    echo "CONFIG_USE_FDPIC=y" >> $config_target_mak
+fi
 
 done # for target in $targets
 
diff --git a/include/elf.h b/include/elf.h
index c0dc9bb..934dbbd 100644
--- a/include/elf.h
+++ b/include/elf.h
@@ -1483,6 +1483,7 @@  typedef struct elf64_shdr {
 #define ELFOSABI_TRU64          10      /* Compaq TRU64 UNIX.  */
 #define ELFOSABI_MODESTO        11      /* Novell Modesto.  */
 #define ELFOSABI_OPENBSD        12      /* OpenBSD.  */
+#define ELFOSABI_ARM_FDPIC      65      /* ARM FDPIC */
 #define ELFOSABI_ARM            97      /* ARM */
 #define ELFOSABI_STANDALONE     255     /* Standalone (embedded) application */
 
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 23e3495..7ba3795 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -1658,6 +1658,14 @@  static void zero_bss(abi_ulong elf_bss, abi_ulong last_bss, int prot)
 }
 
 #ifdef CONFIG_USE_FDPIC
+
+#ifdef TARGET_ARM
+static int elf_is_fdpic(struct elfhdr *exec)
+{
+    return exec->e_ident[EI_OSABI] == ELFOSABI_ARM_FDPIC;
+}
+#endif
+
 static abi_ulong loader_build_fdpic_loadmap(struct image_info *info, abi_ulong sp)
 {
     uint16_t n;