bug-mes
[Top][All Lists]
Advanced

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

libc-mini.a should also include integer division algorithm


From: Danny Milosavljevic
Subject: libc-mini.a should also include integer division algorithm
Date: Thu, 28 May 2020 14:31:40 +0200

Hi,

in mes on branch "wip-arm" some tests were failing because it didn't find the 
integer division function.  It turns out that libc-mini.a doesn't contain 
it--and some of the tests use libc-mini.a.  Some other tests don't use any 
libc--those are in an even worse situation.

The patch at the bottom of this E-Mail would make all tests that use integer 
division but one work.

However, I'm not sure that that's the better solution.

Choices we have:

(1) To include div.c in crt1.c and thus have it always available--but right now 
that would mean that assertion failure and printing to the console have to be 
possible, too (they are used by div.c right now).
(2) To make tests use libc-mini at least.

I think that (1) is the less awful choice.  I think it should be fine to also 
just leave the division by zero handler in libc and fail if we don't have any 
such handler when linking.

So we would split up lib/mes/div.c into two parts.  __mesabi_div0 would go into 
libc and libc-mini; __mesabi_uldiv would go into crt1.  ldiv I wonder about.
How do other compilers do it?

Also interesting to note is that the following is not allowed by gcc:

struct foo {
};

int main() {
        struct foo* x;
        return (x + 1) - x;
}

y.c:7:17: error: arithmetic on pointer to an empty aggregate
    7 |  return (x + 1) - x;

Note:

Integer division is emitted by the our pointer subtractor.

There, division by zero is impossible at runtime because it is caught before 
runtime.

Pointer subtraction CAN give a negative result so our emitter is incorrect 
because right now it assumes that the divident and divisor are always positive.

diff --git a/build-aux/configure-lib.sh b/build-aux/configure-lib.sh
index ed0e23bb..9c03f29f 100644
--- a/build-aux/configure-lib.sh
+++ b/build-aux/configure-lib.sh
@@ -32,6 +32,8 @@ fi
 libc_mini_shared_SOURCES="
 lib/mes/eputs.c
 lib/mes/oputs.c
+lib/mes/__assert_fail.c
+lib/mes/div.c
 "
 
 if test $mes_libc = mes; then

Attachment: pgpgWW5vda0k8.pgp
Description: OpenPGP digital signature


reply via email to

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