After upgrading to ghc 8.0 on a RECENT ubuntu machine, I got the following build error:
在最近的ubuntu机器上升级到ghc 8.0之后,我得到了以下的构建错误:
/usr/bin/ld: -r and -pie may not be used together
/usr/bin/ld: -r和-pie可能不会一起使用。
A different error message for the same problem is:
同一问题的另一个错误信息是:
relocation R_X86_64_32 against `.rodata' can not be used when making a > shared object; recompile with -fPIC
搬迁R_X86_64_32反对”。在制作>共享对象时不能使用rodata;编译与fpic
Is this a known bug? Are there other solutions?
这是已知的错误吗?有其他的解决方案吗?
2 个解决方案
#1
2
The solution is to use the linker flag "-no-pie":
解决方案是使用链接器标记“-no-pie”:
cabal -v --ghc-option="-optl-no-pie" install cabal-install
Is suspect it is perhaps an implicit LD flag that is set on ubuntu that is conflicting somehow.
怀疑它可能是在ubuntu上设置的一个隐含的LD标志,这是相互冲突的。
#2
0
Okay, this is an incredibly! hacky solution, but it did get me past the immediate problem of not being able to build grub. It should work for any other app, but it's so! hacky, I wouldn't leave this in place for very long.
好吧,这真是难以置信!hacky解决方案,但是它确实让我克服了无法构建grub的紧迫问题。它应该适用于任何其他应用程序,但它是如此!hacky,我不会把这个放在很长时间。
I realize the poster's question is about cabal, not grub. But the problem affects multiple programs and the "correct" solution of using the -fno-pie compiler flag doesn't actually work. Apparently the latest version of gcc sets "pie" on by default, and this takes precedence over the -fno-pie flag. Or at least sometimes.
我意识到海报的问题是关于阴谋,而不是食物。但是这个问题影响了多个程序,使用-fno-pie编译器标志的“正确”解决方案实际上并没有起作用。显然,最新版本的gcc在默认情况下设置了“pie”,这比-fno-pie标志优先。或者至少有时。
Here is my working hack for gcc version 6.2.0-5ubuntu12, lubuntu 16.10 (yakkety), linux kernel 4.8.0-22... to build grub 2.02~beta3:
这是我的gcc版本6.2.0-5ubuntu12, lubuntu 16.10 (yakkety), linux内核4.8.0-22…建立grub 2.02 ~ beta3:
# TO HACK
sudo cp /usr/bin/gcc /usr/bin/gcc.orig
sudo cp /usr/bin/gcc /usr/bin/gcc.patch
sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc.patch /usr/bin/gcc
sudo bless /usr/bin/gcc.patch
# search and replace "-pie -z now" with "-v -z now" (see below)
# save changes and exit 'bless'
That is, use the 'bless' hex editor to search for the text string -pie -z now and change that string to read -v -z now making sure to replace "pie" with "v space space" so it takes up the EXACT same number of characters.
也就是说,使用“bless”hex编辑器来搜索文本字符串-pie -z,然后将该字符串改为read -v -z,以确保将“pie”替换为“v space space”,因此它占用了相同数量的字符。
What this does is hack the compiler into sending -v to the linker instead of -pie. If you want to see for yourself what the compiler's doing, just include -Q -v in your compiler's CFLAGS list, and read closely. Even if you specify -fno-pie, the dang thing will still toss out a -pie option to the linker. Anyway, be sure to put everything back when you're done.
这样做的目的是让编译器将-v发送到链接器而不是-pie。如果您想亲自查看编译器的操作,请在编译器的CFLAGS列表中包含-Q -v,并仔细阅读。即使你指定了-fno-pie,党仍然会抛出一个-pie选项给链接器。不管怎样,当你做完了,一定要把所有的东西都放回去。
# UNDO THE HACK
sudo ln -f -s /usr/bin/gcc.orig /usr/bin/gcc
.
。
# REDO THE HACK
sudo ln -f -s /usr/bin/gcc.patch /usr/bin/gcc
#1
2
The solution is to use the linker flag "-no-pie":
解决方案是使用链接器标记“-no-pie”:
cabal -v --ghc-option="-optl-no-pie" install cabal-install
Is suspect it is perhaps an implicit LD flag that is set on ubuntu that is conflicting somehow.
怀疑它可能是在ubuntu上设置的一个隐含的LD标志,这是相互冲突的。
#2
0
Okay, this is an incredibly! hacky solution, but it did get me past the immediate problem of not being able to build grub. It should work for any other app, but it's so! hacky, I wouldn't leave this in place for very long.
好吧,这真是难以置信!hacky解决方案,但是它确实让我克服了无法构建grub的紧迫问题。它应该适用于任何其他应用程序,但它是如此!hacky,我不会把这个放在很长时间。
I realize the poster's question is about cabal, not grub. But the problem affects multiple programs and the "correct" solution of using the -fno-pie compiler flag doesn't actually work. Apparently the latest version of gcc sets "pie" on by default, and this takes precedence over the -fno-pie flag. Or at least sometimes.
我意识到海报的问题是关于阴谋,而不是食物。但是这个问题影响了多个程序,使用-fno-pie编译器标志的“正确”解决方案实际上并没有起作用。显然,最新版本的gcc在默认情况下设置了“pie”,这比-fno-pie标志优先。或者至少有时。
Here is my working hack for gcc version 6.2.0-5ubuntu12, lubuntu 16.10 (yakkety), linux kernel 4.8.0-22... to build grub 2.02~beta3:
这是我的gcc版本6.2.0-5ubuntu12, lubuntu 16.10 (yakkety), linux内核4.8.0-22…建立grub 2.02 ~ beta3:
# TO HACK
sudo cp /usr/bin/gcc /usr/bin/gcc.orig
sudo cp /usr/bin/gcc /usr/bin/gcc.patch
sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc.patch /usr/bin/gcc
sudo bless /usr/bin/gcc.patch
# search and replace "-pie -z now" with "-v -z now" (see below)
# save changes and exit 'bless'
That is, use the 'bless' hex editor to search for the text string -pie -z now and change that string to read -v -z now making sure to replace "pie" with "v space space" so it takes up the EXACT same number of characters.
也就是说,使用“bless”hex编辑器来搜索文本字符串-pie -z,然后将该字符串改为read -v -z,以确保将“pie”替换为“v space space”,因此它占用了相同数量的字符。
What this does is hack the compiler into sending -v to the linker instead of -pie. If you want to see for yourself what the compiler's doing, just include -Q -v in your compiler's CFLAGS list, and read closely. Even if you specify -fno-pie, the dang thing will still toss out a -pie option to the linker. Anyway, be sure to put everything back when you're done.
这样做的目的是让编译器将-v发送到链接器而不是-pie。如果您想亲自查看编译器的操作,请在编译器的CFLAGS列表中包含-Q -v,并仔细阅读。即使你指定了-fno-pie,党仍然会抛出一个-pie选项给链接器。不管怎样,当你做完了,一定要把所有的东西都放回去。
# UNDO THE HACK
sudo ln -f -s /usr/bin/gcc.orig /usr/bin/gcc
.
。
# REDO THE HACK
sudo ln -f -s /usr/bin/gcc.patch /usr/bin/gcc