2012年6月17日 星期日

Prepare Eglibc source code ....

What is eglibc ?
Embedded GLIBC (EGLIBC) is a variant of the GNU C Library (GLIBC) that is designed to work well on embedded systems.
http://www.eglibc.org/home

因為我們產品是 Embedded System . 所以放棄 glibc , 選 eglibc .
相同的 , 我們先要進行一些 patch , patch 的內容如下:

Submitted By: Jim Gifford (jim at cross-lfs dot org)
Date: 07-26-2009
Initial Package Version: 2.10.1
Origin: Upstream
Upstream Status: Applied
Description: These are fixes eglibc-2.10.1, and should be
rechecked periodically.

diff -Naur libc.orig/elf/ldd.bash.in libc/elf/ldd.bash.in
--- libc.orig/elf/ldd.bash.in 2009-02-13 13:31:14.533608000 -0500
+++ libc/elf/ldd.bash.in 2009-07-26 17:57:12.160403278 -0400
@@ -1,4 +1,4 @@
-#! @BASH@
+#! /bin/bash
# Copyright (C) 1996-2008, 2009 Free Software Foundation, Inc.
# This file is part of the GNU C Library.

diff -Naur libc.orig/libio/Makefile libc/libio/Makefile
--- libc.orig/libio/Makefile 2009-07-02 16:03:14.096441000 -0400
+++ libc/libio/Makefile 2009-07-26 17:57:12.160403278 -0400
@@ -170,6 +170,7 @@
tst-fopenloc-ENV = LOCPATH=$(common-objpfx)localedata \
MALLOC_TRACE=$(objpfx)tst-fopenloc.mtrace
tst-fgetws-ENV = LOCPATH=$(common-objpfx)localedata
+tst-fgetwc-ENV = LOCPATH=$(common-objpfx)localedata
tst-ungetwc1-ENV = LOCPATH=$(common-objpfx)localedata
tst-ungetwc2-ENV = LOCPATH=$(common-objpfx)localedata
bug-ungetwc2-ENV = LOCPATH=$(common-objpfx)localedata
diff -Naur libc.orig/sunrpc/Makefile libc/sunrpc/Makefile
--- libc.orig/sunrpc/Makefile 2008-04-25 07:12:05.875033000 -0400
+++ libc/sunrpc/Makefile 2009-07-26 17:57:12.157073385 -0400
@@ -144,11 +144,11 @@
$(+link)

$(addprefix $(objpfx)cross-,$(rpcgen-objs)): $(objpfx)cross-%.o: %.c
- gcc $< -c -D_RPC_THREAD_SAFE_ -D_CROSS_RPCGEN_ \
+ $(BUILD_CC) $< -c -D_RPC_THREAD_SAFE_ -D_CROSS_RPCGEN_ \
$(OUTPUT_OPTION) $(compile-mkdep-flags)

$(objpfx)cross-rpcgen: $(addprefix $(objpfx)cross-,$(rpcgen-objs))
- gcc $^ -o $@
+ $(BUILD_CC) $^ -o $@

# This makes sure -DNOT_IN_libc is passed for all these modules.
cpp-srcs-left := $(rpcgen-objs:.o=.c)
diff -Naur libc.orig/timezone/Makefile libc/timezone/Makefile
--- libc.orig/timezone/Makefile 2009-03-03 08:14:09.770962000 -0500
+++ libc/timezone/Makefile 2009-07-26 17:57:12.157073385 -0400
@@ -181,11 +181,11 @@
$(objpfx)zic: $(addprefix $(objpfx), $(zic-objs))

$(addprefix $(objpfx)cross-,$(zic-objs)): $(objpfx)cross-%.o: %.c
- gcc $< -c $(OUTPUT_OPTION) $(CFLAGS-$*.c) $(CPPFLAGS-$*) \
+ $(BUILD_CC) $< -c $(OUTPUT_OPTION) $(CFLAGS-$*.c) $(CPPFLAGS-$*) \
-DCROSS_ZIC $(compile-mkdep-flags)

$(objpfx)cross-zic: $(addprefix $(objpfx)cross-,$(zic-objs))
- gcc $(addprefix $(objpfx)cross-,$(zic-objs)) -o $@
+ $(BUILD_CC) $(addprefix $(objpfx)cross-,$(zic-objs)) -o $@

tz-cflags = -DTZDIR='"$(zonedir)"' \
-DTZDEFAULT='"$(localtime-file)"' \



接著 , 我們要將 eglibc-ports-2.10.1-20090726-r8632.tar.bz2 也解縮到 eglic 的 source tree 中.

另外 , 也需要對Makeconfig 檔案進行 patch .
cp -v Makeconfig Makeconfig.orig ;
sed -e 's/-lgcc_eh//g' Makeconfig.orig > Makeconfig ;
這樣就準備好了 eglibc 的 source code 了 !!

可以進行下一個階段了 ...... !!

Prepare Kernel Header ....

在進行下一步驟前 , 我們要先準備kernel header .
最好 kernel version 和最後 Target 要使用的 kernel 版本最好一樣 , 不然 會遇到一些奇怪的 bug !
例如 , 之前使用 kernel 2.6.21 (for S3c2416 ARM 用) , 其中
include/linux/input.h 中定義
#define EV_VERSION 0x010000
但是 ... kernel 3.2.0 確定譯
#define EV_VERSION 0x010001
不巧的 , TS_LIB 確有使用這個定義 , 所以如果 Toolchain 用 2.6.21 , Target 確使用 3.2.0 , 可能就會發生這樣的 bug !! 不多說 , 開始說明如何準備 kernel header 吧 !!

A. make mrproper
清除所有設定....

B. make headers_check
開始準備 header file .

C. make CROSS_COMPILE=${CLFS_TARGET}- INSTALL_HDR_PATH=$(PREFIX)/usr/ headers_install
用製作出來的 cross compile 來編譯kernel header , 並且安裝到 perfix/usr/ 下 !!
D . 移除一些沒用的file

find $(PREFIX)/usr/include -name ".install" -or -name "..install.cmd" | xargs rm -fv ;\

大功告成 .....準備下一個階段 ~~~

2012年6月15日 星期五

Building GCC Stage 1

接著 , 要進行主要的 GCC Compiler 了 !!
首先要 Build 出 第一階段的 Cross Compiler. 這個階段的 Cross Compiler 不需要 glibc !!
當然才有辦法用這個 Cross Compiler 進行 eglibc / glibc 的 Compiler !!
GCC 的文件說明 , 建議在 Source Code 外部編譯 , 在我的Source Tree 中 先準備一個 GCC 的Source , 並且進行 下列的 patch :

Submitted By: Jim Gifford (jim at cross-lfs dot org)
Date: 07-22-2009
Initial Package Version: 4.4.1
Origin: Upstream
Upstream Status: Applied
Description: This is a branch update for gcc-4.4.1, and should be
rechecked periodically.

This patch was made from Revision # 149965.

diff -Naur gcc-4.4.1.orig/gcc/resource.c gcc-4.4.1/gcc/resource.c
--- gcc-4.4.1.orig/gcc/resource.c 2009-05-21 16:17:37.000000000 -0700
+++ gcc-4.4.1/gcc/resource.c 2009-07-22 16:22:24.000000000 -0700
@@ -945,10 +945,11 @@

/* If we found a basic block, get the live registers from it and update
them with anything set or killed between its start and the insn before
- TARGET. Otherwise, we must assume everything is live. */
+ TARGET; this custom life analysis is really about registers so we need
+ to use the LR problem. Otherwise, we must assume everything is live. */
if (b != -1)
{
- regset regs_live = df_get_live_in (BASIC_BLOCK (b));
+ regset regs_live = DF_LR_IN (BASIC_BLOCK (b));
rtx start_insn, stop_insn;

/* Compute hard regs live at start of block. */
@@ -1052,7 +1053,7 @@
{
HARD_REG_SET extra_live;

- REG_SET_TO_HARD_REG_SET (extra_live, df_get_live_in (bb));
+ REG_SET_TO_HARD_REG_SET (extra_live, DF_LR_IN (bb));
IOR_HARD_REG_SET (current_live_regs, extra_live);
}
}
diff -Naur gcc-4.4.1.orig/gcc/testsuite/gcc.c-torture/compile/pr40321.c gcc-4.4.1/gcc/testsuite/gcc.c-torture/compile/pr40321.c
--- gcc-4.4.1.orig/gcc/testsuite/gcc.c-torture/compile/pr40321.c 1969-12-31 16:00:00.000000000 -0800
+++ gcc-4.4.1/gcc/testsuite/gcc.c-torture/compile/pr40321.c 2009-07-22 07:45:21.000000000 -0700
@@ -0,0 +1,12 @@
+struct X { int flag; int pos; };
+int foo(struct X *a, struct X *b)
+{
+ while (1)
+ {
+ if (a->flag)
+ break;
+ ({ struct X *tmp = a; a = b; b = tmp; });
+ }
+
+ return a->pos + b->pos;
+}
diff -Naur gcc-4.4.1.orig/gcc/testsuite/g++.dg/torture/pr40321.C gcc-4.4.1/gcc/testsuite/g++.dg/torture/pr40321.C
--- gcc-4.4.1.orig/gcc/testsuite/g++.dg/torture/pr40321.C 1969-12-31 16:00:00.000000000 -0800
+++ gcc-4.4.1/gcc/testsuite/g++.dg/torture/pr40321.C 2009-07-22 07:45:21.000000000 -0700
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+
+struct VectorD2
+{
+ VectorD2() : x(0), y(0) { }
+ VectorD2(int _x, int _y) : x(_x), y(_y) { }
+ int x, y;
+ int GetLength2() const { return x*x + y*y; };
+ VectorD2 operator+(const VectorD2 vec) const {
+ return VectorD2(x+vec.x,y+vec.y);
+ }
+};
+struct Shape
+{
+ enum Type { ST_RECT, ST_CIRCLE } type;
+ VectorD2 pos;
+ VectorD2 radius;
+ bool CollisionWith(const Shape& s) const;
+};
+bool Shape::CollisionWith(const Shape& s) const
+{
+ if(type == ST_CIRCLE && s.type == ST_RECT)
+ return s.CollisionWith(*this);
+ return (pos + s.pos).GetLength2() < (radius + s.radius).GetLength2();
+}
diff -Naur gcc-4.4.1.orig/gcc/tree-ssa-pre.c gcc-4.4.1/gcc/tree-ssa-pre.c
--- gcc-4.4.1.orig/gcc/tree-ssa-pre.c 2009-02-20 07:20:38.000000000 -0800
+++ gcc-4.4.1/gcc/tree-ssa-pre.c 2009-07-22 07:45:21.000000000 -0700
@@ -3507,11 +3507,7 @@
}


-/* Add OP to EXP_GEN (block), and possibly to the maximal set if it is
- not defined by a phi node.
- PHI nodes can't go in the maximal sets because they are not in
- TMP_GEN, so it is possible to get into non-monotonic situations
- during ANTIC calculation, because it will *add* bits. */
+/* Add OP to EXP_GEN (block), and possibly to the maximal set. */

static void
add_to_exp_gen (basic_block block, tree op)
@@ -3523,9 +3519,7 @@
return;
result = get_or_alloc_expr_for_name (op);
bitmap_value_insert_into_set (EXP_GEN (block), result);
- if (TREE_CODE (op) != SSA_NAME
- || gimple_code (SSA_NAME_DEF_STMT (op)) != GIMPLE_PHI)
- bitmap_value_insert_into_set (maximal_set, result);
+ bitmap_value_insert_into_set (maximal_set, result);
}
}

@@ -3544,6 +3538,20 @@
add_to_value (get_expr_value_id (e), e);
bitmap_insert_into_set (PHI_GEN (block), e);
bitmap_value_insert_into_set (AVAIL_OUT (block), e);
+ if (!in_fre)
+ {
+ unsigned i;
+ for (i = 0; i < gimple_phi_num_args (phi); ++i)
+ {
+ tree arg = gimple_phi_arg_def (phi, i);
+ if (TREE_CODE (arg) == SSA_NAME)
+ {
+ e = get_or_alloc_expr_for_name (arg);
+ add_to_value (get_expr_value_id (e), e);
+ bitmap_value_insert_into_set (maximal_set, e);
+ }
+ }
+ }
}
}

@@ -4254,11 +4262,12 @@
FOR_ALL_BB (bb)
{
print_bitmap_set (dump_file, EXP_GEN (bb), "exp_gen", bb->index);
- print_bitmap_set (dump_file, TMP_GEN (bb), "tmp_gen",
- bb->index);
- print_bitmap_set (dump_file, AVAIL_OUT (bb), "avail_out",
- bb->index);
+ print_bitmap_set (dump_file, PHI_GEN (bb), "phi_gen", bb->index);
+ print_bitmap_set (dump_file, TMP_GEN (bb), "tmp_gen", bb->index);
+ print_bitmap_set (dump_file, AVAIL_OUT (bb), "avail_out", bb->index);
}
+
+ print_bitmap_set (dump_file, maximal_set, "maximal", 0);
}

/* Insert can get quite slow on an incredibly large number of basic
diff -Naur gcc-4.4.1.orig/gcc/version.c gcc-4.4.1/gcc/version.c
--- gcc-4.4.1.orig/gcc/version.c 2007-08-21 08:35:30.000000000 -0700
+++ gcc-4.4.1/gcc/version.c 2009-07-22 17:04:03.000000000 -0700
@@ -14,4 +14,4 @@
Makefile. */

const char version_string[] = BASEVER DATESTAMP DEVPHASE REVISION;
-const char pkgversion_string[] = PKGVERSION;
+const char pkgversion_string[] = "(GCC for Cross-LFS 4.4.1.20090722) ";
diff -Naur gcc-4.4.1.orig/libstdc++-v3/include/std/valarray gcc-4.4.1/libstdc++-v3/include/std/valarray
--- gcc-4.4.1.orig/libstdc++-v3/include/std/valarray 2009-04-09 16:23:07.000000000 -0700
+++ gcc-4.4.1/libstdc++-v3/include/std/valarray 2009-07-22 03:25:53.000000000 -0700
@@ -1,7 +1,7 @@
// The template and inlines for the -*- C++ -*- valarray class.

// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-// 2006, 2007, 2009
+// 2006, 2007, 2008, 2009
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -647,7 +647,7 @@
template
inline
valarray<_Tp>::valarray(initializer_list<_Tp> __l)
- : _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size()))
+ : _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size()))
{ std::__valarray_copy_construct (__l.begin(), __l.end(), _M_data); }
#endif

@@ -681,6 +681,7 @@
{
_GLIBCXX_DEBUG_ASSERT(_M_size == __l.size());
std::__valarray_copy(__l.begin(), __l.size(), _M_data);
+ return *this;
}
#endif

接著就可以進行 Compiler GCC Stage 1 了 :

A. 進行 Configure.
AR=ar LDFLAGS="-Wl,-rpath=${PREFIX}/$(TOOLCHAIN_DIR)/lib" \
$(SRC_VERSION)/configure \
--prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
--build=$(CLFS_HOST) --host=$(CLFS_HOST) --target=$(CLFS_TARGET) \
--with-sysroot=$(SYSROOT_PATH) \
--with-gmp=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-mpfr=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-ppl=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-cloog=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-newlib \
--without-headers \
--disable-multilib --disable-nls --disable-decimal-float \
--disable-libgomp --disable-libmudflap --disable-libssp \
--disable-shared --disable-threads \
--enable-languages="c"

其中要指定 -Wl,-rpath=${PREFIX}/$(TOOLCHAIN_DIR)/lib , rpath 是告訴 Compiler 將來 Run Time 時候要到哪去 載 so file . 如果妹有這個設定 , 將來 run time 時候會到 /lib 下尋找 so lib . 也就是說 , 將來這個 ToolChain 要固定 資料夾位置 , 不能任意換位置 .

B . make all-gcc all-target-libgcc
make 過程 , 我們只需要 gcc 和 libgcc 就好 , 其它的不 make .

C. make install-gcc install-target-libgcc
一樣只要 install gcc 和 libgcc 就好 ..

這樣就完成第一階段的 GCC Cross Compiler 了 ~~~~

2012年6月14日 星期四

Building binutils ....

The GNU Binutils are a collection of binary tools. The main ones are:

  • ld - the GNU linker.
  • as - the GNU assembler

這個 library 也是只有 compile 過程會使用到 , 不過這個 library 已經和 Target 有先關聯了 !

A. 先執行 configure .

AR=ar AS=as ../$(SRC_VERSION)/configure \
--prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
--host=$(CLFS_HOST) --target=$(CLFS_TARGET) \
--with-sysroot=$(SYSROOT_PATH) \
--disable-werror

其中 --disable-werror 設定是讓 warning 產生時可以繼續 , 不要有 warning 就停止 .

因為這時候的AS 還沒產生(Target 要用的 ) 所以要指定AS 先用 Host 平台的.


B. make & make install



Building cloog-ppl

CLooG is a free software and library to generate code for scanning Z-polyhedra.

相同的 , 這個 Library , 並不用安裝到 Target Board 上 , 只是 Build ToolChain 過程需要使用到 .
就如同一般library 一樣的安裝 :

A. 先執行 configure .
LDFLAGS= ../$(SRC_VERSION)/configure \
--prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-gmp=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-bits=gmp \
--with-ppl=$(PREFIX)/$(TOOLCHAIN_DIR)


注意 , --with-bits=gmp 要設定 , 不然編譯過程會有錯誤 !!



B. make & make install

2012年6月12日 星期二

Building Parma Polyhedra Library (PPL)

Parma Polyhedra Library (PPL) version 0.11

相同的 , 這個 Library ,  並不用安裝到 Target Board 上 , 只是 Build ToolChain 過程需要使用到 .
就如同一般library 一樣的安裝 :

A.  先執行 configure .
  LDFLAGS=   ../$(SRC_VERSION)/configure \
                                --prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
                                --with-libgmp-prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
                                --with-libgmpxx-prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
                                --disable-optimization \
                                --enable-interfaces="c,cxx"

注意  , 一樣要指定 gmp & gmpxx 的位置 ,  其中 我使用不 optimization  的方式 , 少了這項我也不確定會不會 working , 一開始就使用不 optimization 的方式  .


B. make   &  make install

Building mpfr

The MPFR library is a C library formultiple-precision floating-point computations with correct rounding .
相同的 , 這個 Library , 並不用安裝到 Target Board 上 , 只是 Build ToolChain 過程需要使用到 .
就如同一般library 一樣的安裝 :

A. 先執行 configure .
LDFLAGS= ../$(SRC_VERSION)/configure \
--prefix=$(PREFIX)/$(TOOLCHAIN_DIR) \
--with-gmp=$(PREFIX)/$(TOOLCHAIN_DIR)

這邊需要注意一下 --with-gmp 參數 , 指定剛剛 build 出來的 gmp 位置 .

B. make & make install
C. 會在 所設定的 prefix 看到 mpfr的 library .


另外 , mpfr 在 build 前要先進行一些小 patch 的動作 , patch 的內容可以參考
http://trac.cross-lfs.org/wiki/news#AnnouncingCLFS1.2.0FinalRelease
path 不會很多 , 所以貼在下列 :


Submitted By: Jim Gifford (jim at cross-lfs dot org)
Date: 2009-04-15
Initial Package Version: 2.4.1
Origin: MPFR Website
Upstream Status: Fixed
Description: See http://www.mpfr.org Website Under Bugs

diff -Naur mpfr-2.4.1.orig/mpfr-gmp.c mpfr-2.4.1/mpfr-gmp.c
--- mpfr-2.4.1.orig/mpfr-gmp.c 2009-02-20 01:43:17.000000000 -0800
+++ mpfr-2.4.1/mpfr-gmp.c 2009-04-15 08:27:58.199729850 -0700
@@ -301,7 +301,7 @@
if (linenum != -1)
fprintf (stderr, "%d: ", linenum);
}
- fprintf (stderr, " assertion failed: %s\n", expr);
+ fprintf (stderr, "MPFR assertion failed: %s\n", expr);
abort();
}

diff -Naur mpfr-2.4.1.orig/mpfr.h mpfr-2.4.1/mpfr.h
--- mpfr-2.4.1.orig/mpfr.h 2009-02-25 08:16:08.000000000 -0800
+++ mpfr-2.4.1/mpfr.h 2009-04-15 08:27:58.203729291 -0700
@@ -27,7 +27,7 @@
#define MPFR_VERSION_MAJOR 2
#define MPFR_VERSION_MINOR 4
#define MPFR_VERSION_PATCHLEVEL 1
-#define MPFR_VERSION_STRING "2.4.1"
+#define MPFR_VERSION_STRING "2.4.1-p5"

/* Macros dealing with MPFR VERSION */
#define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
diff -Naur mpfr-2.4.1.orig/PATCHES mpfr-2.4.1/PATCHES
--- mpfr-2.4.1.orig/PATCHES 2009-02-20 01:43:17.000000000 -0800
+++ mpfr-2.4.1/PATCHES 2009-04-15 08:27:58.203729291 -0700
@@ -0,0 +1,4 @@
+zeta_ui-shift
+vasprintf-mp_limb_t
+assert
+remainder-neg
diff -Naur mpfr-2.4.1.orig/rem1.c mpfr-2.4.1/rem1.c
--- mpfr-2.4.1.orig/rem1.c 2009-02-20 01:43:17.000000000 -0800
+++ mpfr-2.4.1/rem1.c 2009-04-15 08:27:58.199729850 -0700
@@ -170,7 +170,12 @@
}

if (mpz_cmp_ui (r, 0) == 0)
- inex = mpfr_set_ui (rem, 0, GMP_RNDN);
+ {
+ inex = mpfr_set_ui (rem, 0, GMP_RNDN);
+ /* take into account sign of x */
+ if (signx < 0)
+ mpfr_neg (rem, rem, GMP_RNDN);
+ }
else
{
if (rnd_q == GMP_RNDN)
@@ -190,6 +195,9 @@
*quo += 1;
}
}
+ /* take into account sign of x */
+ if (signx < 0)
+ mpz_neg (r, r);
inex = mpfr_set_z (rem, r, rnd);
/* if ex > ey, rem should be multiplied by 2^ey, else by 2^ex */
MPFR_EXP (rem) += (ex > ey) ? ey : ex;
@@ -198,13 +206,6 @@
if (quo)
*quo *= sign;

- /* take into account sign of x */
- if (signx < 0)
- {
- mpfr_neg (rem, rem, GMP_RNDN);
- inex = -inex;
- }
-
mpz_clear (mx);
mpz_clear (my);
mpz_clear (r);
diff -Naur mpfr-2.4.1.orig/tests/tfprintf.c mpfr-2.4.1/tests/tfprintf.c
--- mpfr-2.4.1.orig/tests/tfprintf.c 2009-02-20 01:43:15.000000000 -0800
+++ mpfr-2.4.1/tests/tfprintf.c 2009-04-15 08:27:58.199729850 -0700
@@ -195,7 +195,7 @@
check_vfprintf (fout, "a. %Pu, b. %c, c. %Zi%Zn", prec, ch, mpz, &mpz);
check_length_with_cmp (6, mpz, 17, mpz_cmp_ui (mpz, 17), Zi);
check_vfprintf (fout, "%% a. %#.0RNg, b. %Qx%Rn, c. %p", mpfr, mpq, &mpfr,
- &i);
+ (void *) &i);
check_length_with_cmp (7, mpfr, 16, mpfr_cmp_ui (mpfr, 16), Rg);

#ifndef NPRINTF_T
diff -Naur mpfr-2.4.1.orig/tests/tprintf.c mpfr-2.4.1/tests/tprintf.c
--- mpfr-2.4.1.orig/tests/tprintf.c 2009-02-20 01:43:15.000000000 -0800
+++ mpfr-2.4.1/tests/tprintf.c 2009-04-15 08:27:58.203729291 -0700
@@ -191,7 +191,8 @@
check_length (5, sz, 34, zu);
check_vprintf ("a. %Pu, b. %c, c. %RUG, d. %Zi%Zn", prec, ch, mpfr, mpz, &mpz);
check_length_with_cmp (6, mpz, 24, mpz_cmp_ui (mpz, 24), Zi);
- check_vprintf ("%% a. %#.0RNg, b. %Qx%Rn c. %p", mpfr, mpq, &mpfr, &i);
+ check_vprintf ("%% a. %#.0RNg, b. %Qx%Rn c. %p",
+ mpfr, mpq, &mpfr, (void *) &i);
check_length_with_cmp (7, mpfr, 16, mpfr_cmp_ui (mpfr, 16), Rg);

#ifndef NPRINTF_T
diff -Naur mpfr-2.4.1.orig/tests/tremquo.c mpfr-2.4.1/tests/tremquo.c
--- mpfr-2.4.1.orig/tests/tremquo.c 2009-02-20 01:43:15.000000000 -0800
+++ mpfr-2.4.1/tests/tremquo.c 2009-04-15 08:27:58.199729850 -0700
@@ -25,6 +25,36 @@

#include "mpfr-test.h"

+static void
+bug20090227 (void)
+{
+ mpfr_t x, y, r1, r2;
+ int inex1, inex2;
+
+ mpfr_init2 (x, 118);
+ mpfr_init2 (y, 181);
+ mpfr_init2 (r1, 140);
+ mpfr_init2 (r2, 140);
+ mpfr_set_si (x, -1, GMP_RNDN);
+ mpfr_set_str_binary (y, "1.100100100001111110110101010001000100001011010001100001000110100110001001100011001100010100010111000000011011100000111001101000100101001000000100100111000001000100010100110011111010");
+ inex1 = mpfr_remainder (r1, x, y, GMP_RNDU);
+ /* since the quotient is -1, r1 is the rounding of x+y */
+ inex2 = mpfr_add (r2, x, y, GMP_RNDU);
+ if (mpfr_cmp (r1, r2))
+ {
+ printf ("Error in mpfr_remainder (bug20090227)\n");
+ printf ("Expected ");
+ mpfr_dump (r2);
+ printf ("Got ");
+ mpfr_dump (r1);
+ exit (1);
+ }
+ mpfr_clear (x);
+ mpfr_clear (y);
+ mpfr_clear (r1);
+ mpfr_clear (r2);
+}
+
int
main (int argc, char *argv[])
{
@@ -50,6 +80,8 @@

tests_start_mpfr ();

+ bug20090227 ();
+
mpfr_init (x);
mpfr_init (y);
mpfr_init (r);
diff -Naur mpfr-2.4.1.orig/vasprintf.c mpfr-2.4.1/vasprintf.c
--- mpfr-2.4.1.orig/vasprintf.c 2009-02-20 01:43:17.000000000 -0800
+++ mpfr-2.4.1/vasprintf.c 2009-04-15 08:27:58.203729291 -0700
@@ -398,7 +398,7 @@
(void) va_arg ((ap), mpq_srcptr); \
break; \
case MP_LIMB_ARG: \
- (void) va_arg ((ap), mp_ptr); \
+ (void) va_arg ((ap), mp_limb_t); \
break; \
case MP_LIMB_ARRAY_ARG: \
(void) va_arg ((ap), mp_ptr); \
diff -Naur mpfr-2.4.1.orig/VERSION mpfr-2.4.1/VERSION
--- mpfr-2.4.1.orig/VERSION 2009-02-25 08:16:08.000000000 -0800
+++ mpfr-2.4.1/VERSION 2009-04-15 08:27:58.203729291 -0700
@@ -1 +1 @@
-2.4.1
+2.4.1-p5
diff -Naur mpfr-2.4.1.orig/version.c mpfr-2.4.1/version.c
--- mpfr-2.4.1.orig/version.c 2009-02-25 08:16:08.000000000 -0800
+++ mpfr-2.4.1/version.c 2009-04-15 08:27:58.203729291 -0700
@@ -25,5 +25,5 @@
const char *
mpfr_get_version (void)
{
- return "2.4.1";
+ return "2.4.1-p5";
}
diff -Naur mpfr-2.4.1.orig/zeta_ui.c mpfr-2.4.1/zeta_ui.c
--- mpfr-2.4.1.orig/zeta_ui.c 2009-02-20 01:43:17.000000000 -0800
+++ mpfr-2.4.1/zeta_ui.c 2009-04-15 08:27:58.203729291 -0700
@@ -177,7 +177,9 @@
mpz_mul_ui (t, t, 2 * k - 1);
}
mpz_div_2exp (t, t, 1);
- if (n < 1UL << (BITS_PER_MP_LIMB / 2))
+ /* Warning: the test below assumes that an unsigned long
+ has no padding bits. */
+ if (n < 1UL << ((sizeof(unsigned long) * CHAR_BIT) / 2))
/* (n - k + 1) * (n + k - 1) < n^2 */
mpz_divexact_ui (t, t, (n - k + 1) * (n + k - 1));
else