bug-mes
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mes call encoding bug with struct return


From: Danny Milosavljevic
Subject: mes call encoding bug with struct return
Date: Mon, 8 Jun 2020 12:43:46 +0200

Hi,

when encoding a function call, mescc assumes that a huge struct fits into a
register directly.  That is not actually possible.

Example:

typedef struct
{
  long quot;
  long rem;
} ldiv_t;

ldiv_t __mesabi_ldiv(long a, long b) {
  ldiv_t result = {2,3};
  return result;
}

long
__aeabi_idiv (long a, long b)
{
  ldiv_t result = __mesabi_ldiv(a, b); // actual result: Call is encoded as if 
RESULT can fit into r0, which is not possible.
  return result.quot; // actual result: not 2
}

That means at runtime we will get an erroneous result.

On the other hand, GCC automatically converts that into:

  void __mesabi_ldiv(long a, long b, ldiv_t* result);

long
__aeabi_idiv (long a, long b)
{
  ldiv_t result;
  __mesabi_ldiv(a, b, &result);
  return result.quot;
}

Possible fixes in mescc:

* Fail with an error message when someone tries to use that, or
* Implement the same way as GCC does

Attachment: pgpaoavogIbrt.pgp
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]