loongson-2f's bugfix patch have been merged into binutils 2.20.1

58 views
Skip to first unread message

Wu Zhangjin

unread,
Mar 7, 2010, 12:03:26 AM3/7/10
to loongson-dev
Hi, all

Nick Clifton have applied that patch several days ago, thanks goes to
him.

If you don't want to apply that path here:

http://sourceware.org/ml/binutils/2009-11/msg00387.html

please use binutils 2.20.1 directly:

http://ftp.gnu.org/gnu/binutils/

About more information of that patch, please access this page:

http://groups.google.com.hk/group/loongson-dev/browse_thread/thread/cccaf4a86df5d11f

That patch provides two new options for gas, including
-mfix-loongson2f-nop and -mfix-loongson2f-jump, both of them are needed
to compile the kernel, but only the first one is needed to compile the
user-space programs with the help of the related kernel patch [1].

Now, let's have a look at how to use the new patched binutils.

o How to Compile Kernel with the patched binutils

If you want to cross-compile the kernel in a x86 system, there was an
exisiting cross-compiler with the patch for you, and there are also
somple resources about how to make one from scratch:

http://dev.lemote.com/code/linux-loongson-community/#Cross-Compile

but if you need to local-compile it, please build your own binutils
2.20.1 at first.

After getting the binary of the patched binutils, please do remember to
use both of the options.

For all of the stable branches in the rt4ls git repository at
http://dev.lemote.com/code/rt4ls, they have already applied the
following three kernel patches to work with the patched binutils. so,
you only need to download/clone and compile them directly with the
patched binutils.

But for the current mainline 2.6.33 and even 2.6.34, they have no such
patch yet, so, if you need the mainline linux, please apply the
following three patches yourselves. but I will upstream them asap.

[1] Loongson: 2F: Make cpu execute predictively
http://dev.lemote.com/cgit/rt4ls.git/commit/?h=rt/2.6.31/mips&id=13cc3656ca9f4d651c9fb3ed2a7ce27b47c51134
[2] Loongson: 2F: enable fixups of binutils
http://dev.lemote.com/cgit/rt4ls.git/commit/?h=rt/2.6.31/mips&id=eaf2747faae3af0609e43af2bd922d15cfd0674f
[3] Loongson: 2F: Fix the reboot problem introduced by the patch of
binutils
http://dev.lemote.com/cgit/rt4ls.git/commit/?h=rt/2.6.31/mips&id=4f7685df814d648acc315cc5fc044072ac38b8fe

o How to compile user-space applications

As described above, we only need the -mfix-loongson2f-nop option to
compile the user-space applications, that option did a very stupid job:
just replace the nop instruction by a "or at, at, zero"(which is also a
NOP instruction, but workaround the bug) instruction.

So, We can also use a user-space program to replace them(of course, not
work with the dynamically generated instructions...), here is such a
program contributed by Heihaier:

http://dev.lemote.com/code/linux-loongson-community/raw-attachment/wiki/WikiStart/fix-nop.c.tar.gz

If you don't have the binary of the patched binutils, the above tool is
another good option to make your machine not crash, for example, to make
ld, as work well, remove the nop instructions via the following
commands:

$ make fix-nops
$ ./fix-nops `which ld`
$ ./fix-nops `which as`

and for a new application named test, please do:

$ ./fix-nops /path/to/test

and If you have gotten the binary of the patched binutils, compile the
applications with -mfix-loongson2f-nop like this:

$ gcc -mfix-loongson2f-nop ...

or you can put the option into CFLAGS.

o How to use this new binutils for a GNU/Linux distribution developer

In theory, -mfix-loongson2f-nop will not reduce the performance(but need
enough performance testing to compare the cycles needed by the "or at,
at, zero" and "nop" instructions?), so, all of the GNU/Linux
distribution developers are recommended to compile the applications for
MIPS with this option, then the applications for MIPS can work on
Loongson-2F too.

For linux-MIPS can not run on all of the MIPS machines, the GNU/Linux
distribution developers need to compile the Loongson specific linux
kernel. and for all of the current Loongson-2F machines made by Lemote,
there is only a need to compile one kernel image, then enabling both of
the options: -mfix-loongson-nop and -mfix-loongson-jump is needed.

Best Regards,
Wu Zhangjin

Fai Wong

unread,
Mar 7, 2010, 2:09:08 AM3/7/10
to loongs...@googlegroups.com
Hi,

I just applied these patches to Fedora 12's source.
Are there any test cases for the patch so that I can see the "wrong"
and "right" behaviour?

Cheers,
Fai

2010/3/7 Wu Zhangjin <wuzha...@gmail.com>:

> --
> You received this message because you are subscribed to the Google Groups "loongson-dev" group.
> To post to this group, send email to loongs...@googlegroups.com.
> To unsubscribe from this group, send email to loongson-dev...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/loongson-dev?hl=en.
>
>

Zhang Le

unread,
Mar 7, 2010, 3:35:52 AM3/7/10
to loongs...@googlegroups.com

When submitting this patch, don't forget to remove this option:
+ $(call as-option,-Wa$(comma)-mfix-ls2f-kernel,)

Just a reminder, :) Also see below,

> [3] Loongson: 2F: Fix the reboot problem introduced by the patch of
> binutils
> http://dev.lemote.com/cgit/rt4ls.git/commit/?h=rt/2.6.31/mips&id=4f7685df814d648acc315cc5fc044072ac38b8fe
>
> o How to compile user-space applications
>
> As described above, we only need the -mfix-loongson2f-nop option to
> compile the user-space applications, that option did a very stupid job:
> just replace the nop instruction by a "or at, at, zero"(which is also a
> NOP instruction, but workaround the bug) instruction.
>
> So, We can also use a user-space program to replace them(of course, not
> work with the dynamically generated instructions...), here is such a
> program contributed by Heihaier:
>
> http://dev.lemote.com/code/linux-loongson-community/raw-attachment/wiki/WikiStart/fix-nop.c.tar.gz
>
> If you don't have the binary of the patched binutils, the above tool is
> another good option to make your machine not crash, for example, to make
> ld, as work well, remove the nop instructions via the following
> commands:
>
> $ make fix-nops
> $ ./fix-nops `which ld`
> $ ./fix-nops `which as`
>
> and for a new application named test, please do:
>
> $ ./fix-nops /path/to/test
>
> and If you have gotten the binary of the patched binutils, compile the
> applications with -mfix-loongson2f-nop like this:
>
> $ gcc -mfix-loongson2f-nop ...

Actually it should be
$ gcc -Wa,-mfix-loongson2f-nop

Zhang, Le

Wu Zhangjin

unread,
Mar 7, 2010, 7:46:51 AM3/7/10
to loongs...@googlegroups.com
On Sun, 2010-03-07 at 15:09 +0800, Fai Wong wrote:
> Hi,
>
> I just applied these patches to Fedora 12's source.
> Are there any test cases for the patch so that I can see the "wrong"
> and "right" behaviour?

I have written three gas testcases, you can take a look at the source
code: http://sourceware.org/ml/binutils/2009-11/msg00387.html and test
it.

Or For the -mfix-loongson2f-nop, you can try to get the output of
objdump and grep the nop instruction, there should be very few of nops
left(for the ld has hard-coded a nop instruction as 00...000 after the
jump instruction, I have not touched it since it not influence the nop
issue).

$ objdump -d /path/to/app | grep nop

And For the -mfix-loongson2f-jump, You may get some extra instructions
as following before every jump instruction(except the "jr $1") from the
output of objdump.

lui at, ...
ori at, at, ...
and ..., ... , at

Regards,
Wu Zhangjin

Wu Zhangjin

unread,
Mar 7, 2010, 7:49:27 AM3/7/10
to loongs...@googlegroups.com
On Sun, 2010-03-07 at 08:35 +0000, Zhang Le wrote:
[...]

> > [2] Loongson: 2F: enable fixups of binutils
> > http://dev.lemote.com/cgit/rt4ls.git/commit/?h=rt/2.6.31/mips&id=eaf2747faae3af0609e43af2bd922d15cfd0674f
>
> When submitting this patch, don't forget to remove this option:
> + $(call as-option,-Wa$(comma)-mfix-ls2f-kernel,)
>
> Just a reminder, :) Also see below,
>

Of course ;)

> >
> > $ gcc -mfix-loongson2f-nop ...
>
> Actually it should be
> $ gcc -Wa,-mfix-loongson2f-nop
>

Right.

Thanks!
Wu Zhangjin

Fai Wong

unread,
Mar 7, 2010, 8:59:19 AM3/7/10
to loongs...@googlegroups.com
2010/3/7 Wu Zhangjin <wuzha...@gmail.com>:

> Or For the -mfix-loongson2f-nop, you can try to get the output of
> objdump and grep the nop instruction, there should be very few of nops
> left(for the ld has hard-coded a nop instruction as 00...000 after the
> jump instruction, I have not touched it since it not influence the nop
> issue).
>
> $ objdump -d /path/to/app | grep nop
>
> And For the -mfix-loongson2f-jump, You may get some extra instructions
> as following before every jump instruction(except the "jr $1") from the
> output of objdump.
>
> lui at, ...
> ori at, at, ...
> and ..., ... , at
>
> Regards,
>        Wu Zhangjin

Thanks! I used gtk2 as a test, objdump shows 603 nop in gtk-demo
binary, and after adding -mfix-loongson2f-nop, it has reduced to 20,
so my binutils should be alright.

Cheers,
Fai

Deng, Xiyue

unread,
Apr 12, 2010, 11:17:20 PM4/12/10
to loongson-dev

Even the patch is now merge in upstream official releases, bjlx.org.cn is still providing a patched version of binutils. What's that for?

Regards,
Xiyue Deng

Wu Zhangjin

unread,
Apr 12, 2010, 11:28:52 PM4/12/10
to loongs...@googlegroups.com
On Mon, 2010-04-12 at 20:17 -0700, Deng, Xiyue wrote:
[...]

> >
>
> Even the patch is now merge in upstream official releases, bjlx.org.cn is still providing a patched version of binutils. What's that for?

Yeah, Very sorry for my careless, the patch was merged into the cvs repo
of binutils, but not have been in 2.20.1 yet ;) therefore, we may get a
binutils 2.20.2 which do not need the extra patch, but currently, we
need to apply it ourselves if not using the cvs version of binutils.

Regards,
Wu Zhangjin

Alejandro Mery

unread,
Apr 13, 2010, 4:45:13 AM4/13/10
to loongs...@googlegroups.com

It is included in debian experimental binutils-2.20.51.20100405 =)

Wu Zhangjin

unread,
Apr 13, 2010, 5:06:14 AM4/13/10
to loongs...@googlegroups.com

Thanks ;)


Deng, Xiyue

unread,
Apr 21, 2010, 1:36:02 AM4/21/10
to loongson-dev
And now in binutils 2.20.1-6 and later:

binutils (2.20.1-6) unstable; urgency=low
.
[..snip..]
* Backport fixups of Loongson2F from the trunk.

So no need to patch after 2.20.1-7+ enters testing, Yay!


Regards,
Xiyue Deng
Reply all
Reply to author
Forward
0 new messages