1 From ab0d7e270d89f6eb99582197d2d58bf60c9c3d26 Mon Sep 17 00:00:00 2001
2 From: Anton Gerasimov <anton@advancedtelematic.com>
3 Date: Thu, 15 Sep 2016 16:49:32 +0200
4 Subject: [PATCH 2/2] Replace wraps with built-in code to remove dependency on
8 arch/x86/config.mk | 2 --
9 arch/x86/lib/gcc.c | 104 ++++++++++++++++++++++++++++++++++++++++++++---------
10 2 files changed, 87 insertions(+), 19 deletions(-)
12 diff --git a/arch/x86/config.mk b/arch/x86/config.mk
13 index 999143e..139576e 100644
14 --- a/arch/x86/config.mk
15 +++ b/arch/x86/config.mk
16 @@ -22,5 +22,3 @@ PLATFORM_RELFLAGS += -ffunction-sections -fvisibility=hidden
17 PLATFORM_LDFLAGS += --emit-relocs -Bsymbolic -Bsymbolic-functions -m elf_i386
19 LDFLAGS_FINAL += --gc-sections -pie
20 -LDFLAGS_FINAL += --wrap=__divdi3 --wrap=__udivdi3
21 -LDFLAGS_FINAL += --wrap=__moddi3 --wrap=__umoddi3
22 diff --git a/arch/x86/lib/gcc.c b/arch/x86/lib/gcc.c
23 index 497ad75..c321b11 100644
24 --- a/arch/x86/lib/gcc.c
25 +++ b/arch/x86/lib/gcc.c
31 - * GCC's libgcc handling is quite broken. While the libgcc functions
32 - * are always regparm(0) the code that calls them uses whatever the
33 - * compiler call specifies. Therefore we need a wrapper around those
34 - * functions. See gcc bug PR41055 for more information.
36 -#define WRAP_LIBGCC_CALL(type, name) \
37 - type __normal_##name(type a, type b) __attribute__((regparm(0))); \
38 - type __wrap_##name(type a, type b); \
39 - type __attribute__((no_instrument_function)) \
40 - __wrap_##name(type a, type b) \
41 - { return __normal_##name(a, b); }
43 -WRAP_LIBGCC_CALL(long long, __divdi3)
44 -WRAP_LIBGCC_CALL(unsigned long long, __udivdi3)
45 -WRAP_LIBGCC_CALL(long long, __moddi3)
46 -WRAP_LIBGCC_CALL(unsigned long long, __umoddi3)
50 +uint64_t __udivmoddi4 ( uint64_t num,
54 + uint64_t quot = 0, qbit = 1;
57 + return 1/((unsigned)den); /* Intentional divide by zero, without
58 + triggering a compiler warning which
59 + would abort the build */
62 + /* Left-justify denominator and count shift */
63 + while ( (int64_t)den >= 0 ) {
82 +uint64_t __udivdi3( uint64_t num, uint64_t den )
84 + return __udivmoddi4(num, den, NULL);
87 +uint64_t __umoddi3 ( uint64_t num, uint64_t den )
91 + (void) __udivmoddi4(num, den, &v);
95 +int64_t __divmoddi4 ( int64_t num,
111 + v = __udivmoddi4(num, den, (uint64_t *)rem_p);
115 + *rem_p = -(*rem_p);
122 +int64_t __moddi3 (int64_t num, int64_t den)
126 + (void) __divmoddi4(num, den, &v);
130 +int64_t __divdi3(int64_t num, int64_t den)
132 + return __divmoddi4(num, den, NULL);