I’m trying to compile a simple «Hello World» program in Linux using Eclipse, but I always get this:
Building target: hello
Invoking: GCC C++ Linker
g++ -o "hello" ./src/hello.o
./src/hello.o: file not recognized: File truncated
collect2: ld returned 1 exit status
make: *** [hello] Error 1
**** Build Finished ****
Does anyone have an idea what the problem is?
Jagger
10.3k8 gold badges51 silver badges91 bronze badges
asked Apr 19, 2011 at 8:56
Just remove the object file.
This error most likely appeared after the previous build was interrupted and object file was not generated completely.
answered Jul 22, 2013 at 14:15
5
Just as an info if someone comes around here.
Another problem (with the same error) could be, that you are using ccache for faster compilation. In this case, the corrupt *.o file is there as well. So for that reason you have to clean the cache with
ccache -C (note the upper case C!)
Wasted me hours the first time 
answered Feb 9, 2016 at 13:16
RainerRainer
7515 silver badges20 bronze badges
4
I think
g++ -o "hello" ./src/hello.o
should be ./src/hello.(c | cpp | cc depending on your language type)
answered Apr 19, 2011 at 8:59
Vivek GoelVivek Goel
22.3k29 gold badges109 silver badges184 bronze badges
2
I’m just learning GNU make, but I’m having trouble linking when using .d (dependency) files. Can anyone point me in the right direction with this error:
...../part1.o: file not recognized: File truncated
recipe for target 'bin/target/prog' failed
It’s a simple program containing: main.cpp, part1.cpp, part1.h, part2.cpp, part2.h
Where part1 and part2 have a method to print something.
This is from terminal when running make:
I don’t get why I’m getting a warning for using #pragma once?
stud@GoldenImageASE:~/Desktop/ISU/L1/2$ make ARCH=target -f Makefile.th
Compiling...part2.cpp
arm-devkit-g++ -MTbuild/target/part2.o -MM -I. part2.cpp > build/target/part2.d
Compiling...part1.cpp
arm-devkit-g++ -MTbuild/target/part1.o -MM -I. part1.cpp > build/target/part1.d
Compiling...main.cpp
arm-devkit-g++ -MTbuild/target/main.o -MM -I. main.cpp > build/target/main.d
object file....main.o
arm-devkit-g++ -I. -c main.cpp part1.h part2.h > build/target/main.o
part1.h:1:9: warning: #pragma once in main file
#pragma once
^
part2.h:1:9: warning: #pragma once in main file
#pragma once
^
object file....part1.o
arm-devkit-g++ -I. -c part1.cpp > build/target/part1.o
object file....part2.o
arm-devkit-g++ -I. -c part2.cpp > build/target/part2.o
arm-devkit-g++ -I. -o build/target/main.o build/target/part1.o build/target/part2.o -o prog
build/target/part1.o: file not recognized: File truncated
collect2: error: ld returned 1 exit status
Makefile.th:27: recipe for target 'bin/target/prog' failed
make: *** [bin/target/prog] Error 1
My Makefile is found below:
# Variables
SOURCES=main.cpp part1.cpp part2.cpp
OBJECTS=$(SOURCES:.cpp=.o)
DEPS=$(SOURCES:.cpp=.d)
EXE=prog
CXXFLAGS =-I.
# Making for host
# > make ARCH=host
ifeq (${ARCH},host)
CXX=g++
BUILD_DIR=build/host
EXE_DIR=bin/host
endif
# Making for target
# > make ARCH= target
ifeq (${ARCH},target)
CXX=arm-devkit-g++
BUILD_DIR=build/target
EXE_DIR=bin/target
endif
$(addprefix ${EXE_DIR}/,$(EXE)): $(addprefix ${BUILD_DIR}/,$(DEPS)) $(addprefix ${BUILD_DIR}/,$(OBJECTS))
# << Check the $(DEPS) new dependency
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) -o $(addprefix ${BUILD_DIR}/,$(OBJECTS))
$(addprefix $(BUILD_DIR)/, %.o): %.cpp
@echo "object file...."$*.o
$(CXX) $(CXXFLAGS) -c $^ > $@
# Rule that describes how a .d ( dependency ) file is created from a .cpp
# Similar to the assigment %. cpp -> %.o
${BUILD_DIR}/%.d: %.cpp
@mkdir -p $(dir $@)
@echo "Compiling..."$<
$(CXX) -MT$(@:.d=.o) -MM $(CXXFLAGS) $^ > $@
debug:
@echo "DEPS: "$(DEPS)"n"
@echo "OBJ: " $(addprefix ${BUILD_DIR}/,$(OBJECTS))"n"
@echo "EXE: " $(addprefix ${EXE_DIR}/,$(EXE))"n"
.PHONY:clean
clean:
rm -f $(EXE) $(addprefix ${BUILD_DIR}/,$(DEPS)) $(addprefix ${BUILD_DIR}/,$(OBJECTS))
ifneq ($(MAKECMDGOALS),clean)
-include $(addprefix ${BUILD_DIR}/,$(DEPS))
endif
Hello,
I’m getting a linker error with MSYS2 on Windows 10.
Here are the last lines from make output:
...
i686-w64-mingw32-gcc -c -fpermissive -Wno-write-strings -o Source/scrollrt.o Source/scrollrt.cpp
i686-w64-mingw32-gcc -c -fpermissive -Wno-write-strings -o 3rdParty/PKWare/implode.o 3rdParty/PKWare/implode.cpp
i686-w64-mingw32-gcc -c -fpermissive -Wno-write-strings -o 3rdParty/PKWare/explode.o 3rdParty/PKWare/explode.cpp
i686-w64-mingw32-gcc -L./ -o devilution.exe Source/init.o Source/drlg_l4.o Source/stores.o Source/diablo.o Source/dead.o Source/encrypt.o Source/error.o Source/towners.o Source/town.o Source/trigs.o Source/drlg_l1.o Source/setmaps.o Source/help.o Source/effects.o Source/inv.o Source/logging.o Source/sync.o Source/missiles.o Source/player.o Source/minitext.o Source/plrmsg.o Source/nthread.o Source/msg.o Source/automap.o Source/fault.o Source/appfat.o Source/cursor.o Source/monster.o Source/lighting.o Source/quests.o Source/mpqapi.o Source/capture.o Source/track.o Source/sound.o Source/engine.o Source/portal.o Source/themes.o Source/palette.o Source/gamemenu.o Source/sha.o Source/spells.o Source/debug.o Source/loadsave.o Source/restrict.o Source/pack.o Source/world.o Source/multi.o Source/wave.o Source/drlg_l3.o Source/msgcmd.o Source/objects.o Source/dthread.o Source/doom.o Source/items.o Source/path.o Source/dx.o Source/textdat.o Source/pfile.o Source/movie.o Source/codec.o Source/gmenu.o Source/tmsg.o Source/mainmenu.o Source/gendung.o Source/control.o Source/drlg_l2.o Source/interfac.o Source/scrollrt.o 3rdParty/PKWare/implode.o 3rdParty/PKWare/explode.o diabloui.lib storm.lib -lgdi32 -lversion -ldiabloui -lstorm
diabloui.lib: file not recognized: File truncated
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:10: devilution.exe] Error 1
I’ve followed the instructions from Support/INSTALL_windows.md.
$ uname -a
MINGW32_NT-10.0 <HOSTNAME> 2.10.0(0.325/5/3) 2018-02-09 15:25 x86_64 Msys
$ gcc -v
Using built-in specs.
COLLECT_GCC=C:msys64mingw32bingcc.exe
COLLECT_LTO_WRAPPER=C:/msys64/mingw32/bin/../lib/gcc/i686-w64-mingw32/7.3.0/lto-wrapper.exe
Target: i686-w64-mingw32
Configured with: ../gcc-7.3.0/configure --prefix=/mingw32 --with-local-prefix=/mingw32/local --build=i686-w64-mingw32 --host=i686-w64-mingw32 --target=i686-w64-mingw32 --with-native-system-header-dir=/mingw32/i686-w64-mingw32/include --libexecdir=/mingw32/lib --enable-bootstrap --with-arch=i686 --with-tune=generic --enable-languages=c,lto,c++,objc,obj-c++,fortran,ada --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-time=yes --enable-libstdcxx-filesystem-ts=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw32 --with-mpfr=/mingw32 --with-mpc=/mingw32 --with-isl=/mingw32 --with-pkgversion='Rev2, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld --disable-sjlj-exceptions --with-dwarf2
Thread model: posix
gcc version 7.3.0 (Rev2, Built by MSYS2 project)
Any ideas?
|
vitalya199529 0 / 0 / 1 Регистрация: 12.02.2013 Сообщений: 21 |
||||
|
1 |
||||
|
13.11.2013, 14:14. Показов 49279. Ответов 14 Метки нет (Все метки)
господа программисты, объясните мне в чем тут дело, я решил поиграться со счетчиком строк, но вот что то он не запускается
ошибка я видел тему на счет этой ошибки на форуме но внятного решения проблемы так и не увидел
__________________
0 |
|
castaway 4978 / 3085 / 456 Регистрация: 10.11.2010 Сообщений: 11,164 Записей в блоге: 10 |
||||
|
13.11.2013, 14:15 |
2 |
|||
|
Тут, и везде в остальном коде не кавычки должны быть, а два знака <
0 |
|
vitalya199529 0 / 0 / 1 Регистрация: 12.02.2013 Сообщений: 21 |
||||
|
13.11.2013, 14:17 [ТС] |
3 |
|||
|
Тут, и везде в коде не кавычки должны быть, а два знака <
ну так это и есть два знака << просто при копировании кода из devc++ они заменились на «
0 |
|
4978 / 3085 / 456 Регистрация: 10.11.2010 Сообщений: 11,164 Записей в блоге: 10 |
|
|
13.11.2013, 14:19 |
4 |
|
Ты букву Б на клавиатуре видишь?
0 |
|
0 / 0 / 1 Регистрация: 12.02.2013 Сообщений: 21 |
|
|
13.11.2013, 14:21 [ТС] |
5 |
|
так что дело не в этом, у меня да же при всем желании не получается поставить этот знак « только << так, так что ошибка не в этом Добавлено через 45 секунд
Ты букву Б на клавиатуре видишь? у меня да же при всем желании не получается поставить этот знак « только << так, так что ошибка не в этом
0 |
|
4978 / 3085 / 456 Регистрация: 10.11.2010 Сообщений: 11,164 Записей в блоге: 10 |
|
|
13.11.2013, 14:23 |
6 |
|
Ты в Microsoft Word программы пишешь?
0 |
|
vitalya199529 0 / 0 / 1 Регистрация: 12.02.2013 Сообщений: 21 |
||||
|
13.11.2013, 14:23 [ТС] |
7 |
|||
вот так вот у меня код записан в деве Добавлено через 22 секунды
Ты в Microsoft Word программы пишешь? Dev C++
0 |
|
4978 / 3085 / 456 Регистрация: 10.11.2010 Сообщений: 11,164 Записей в блоге: 10 |
|
|
13.11.2013, 14:25 |
8 |
|
В этой программе нет синтаксических ошибок. У меня она компилируется нормально.
0 |
|
0 / 0 / 1 Регистрация: 12.02.2013 Сообщений: 21 |
|
|
13.11.2013, 14:26 [ТС] |
9 |
|
я могу скрин кинуть, только скажите как это сделать))
0 |
|
Почетный модератор 5850 / 2861 / 392 Регистрация: 01.11.2011 Сообщений: 6,905 |
|
|
13.11.2013, 14:31 |
10 |
|
vitalya199529, перепишите код руками. Не копируйте. Руками. Это и полезно вам будет и ошибку устранит.
0 |
|
0 / 0 / 1 Регистрация: 12.02.2013 Сообщений: 21 |
|
|
13.11.2013, 14:37 [ТС] |
11 |
|
проблема решилась сама собой после 100500 попытки запуска все заработало)
0 |
|
0 / 0 / 0 Регистрация: 05.04.2014 Сообщений: 5 |
|
|
08.08.2015, 14:21 |
12 |
|
Надо в диспетчере задач убить процесс своей программы. и запускай
0 |
|
Don’t worry, be happy 17781 / 10545 / 2036 Регистрация: 27.09.2012 Сообщений: 26,516 Записей в блоге: 1 |
|
|
08.08.2015, 14:28 |
13 |
|
Надо в диспетчере задач убить процесс своей программы. и запускай Он за два года еще из цикла не вышел
4 |
|
castaway |
|
08.08.2015, 14:28
|
|
Не по теме:
Он за два года еще из цикла не вышел :D.
0 |
|
0 / 0 / 0 Регистрация: 05.08.2019 Сообщений: 3 |
|
|
05.08.2019, 22:17 |
15 |
|
Он просто консоль забыл вырубить и все
0 |

If you want to become an expert at fixing this undefined reference in your program, keep reading this complete guide that contains all the details.
Why Is the collect2: Error: Ld Returned 1 Exit Status Happening?
This specific collect2: error: ld returned 1 exit status error message appears due to previous errors in your document, especially when working with C++. It represents one of the most common errors web developers face but it is also one of the easiest ones to fix. In other words, this error is there to indicate that the linking step in the process of creating faced certain problems.
This is going to create an undefined reference because the exit status is more than the value of zero. You can run multiple steps to create a search thread that is going to eliminate the problem. We are going to list and explain the various methods you can use to fix this error in your document. Continue reading the following section of this article to learn more about the debugging process.
How To Fix This Error Inside Your Program
The easiest and most common method of fixing this error requires you to completely delete the existing executable file that is running in the background of your program. However, as is the case with most other bugs, this solution might not work for everyone and every single time. Lucky for you, programming languages allow users to fix an error in multiple ways, in case any of the previous ones does not work.
This is called a process of debugging, where you are trying to completely remove an error you have encountered in your program. No matter how serious the error may be, the debugging process always starts with an inspection of the problem. After that, locate where the error is coming from and apply all the necessary changes to the code.
Let us now learn something more about the ways of debugging this error.
– Listing All the Possible Methods for Debugging This Error
In this part of the guide, we are going to list the possible methods for debugging and also briefly explain their function. Let us take a deep dive at the following list that shows the most common ways of fixing this error:
- Deleting the existing executable file inside your program: The file may have failed because it is locked in a different location, such as an antivirus.
- It is possible to try and rename that specific executable file in your program. Then, you are supposed to restructure the contents, and you are done. Renaming the file helps the program to create an additional executable file.
- In case none of this works, you should try restarting your computer and redo the first step. This solution shows that debugging does not always have to be complicated.
In theory, this is all it takes to completely remove this error from your syntax. However, it is always best to learn from examples. That is why in the following section of this article, we are going to show you example codes to easily fix this error.
– A Common Error in the Gem Native Extension
Many web developers face certain problems once working with extensions for their browsers. One such bug appears when you are trying to install a gem inside the native extension on your browser.
The reason why we are explaining the native extension is that the collect2 error usually appears during the process of installing a gem. To better understand what this means, you should take a look at the complete syntax.
Take a closer look at the following code that is going to initiate the collect2 error:
Building a proper native extension. This might take a while…
ERROR: Error installing json:
ERROR: Failed to generate gem native extension.
/home/foobar/.rvm/ruby-2.4.7/bin/ruby -r ./siteconf134617815-3312439-1i9lahdrj.rb extconf.rb
creating Makefile
make “DESTDIR=” clean
make “DESTDIR=”
compiling generator.c
linking shared-object json/ext/generator.so
/usr/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
make: *** [generator.so] Error 1
make failed, exit code 2
Gem files will remain installed in /home/foobar/.rvm/gems/ruby-2.4.7/gems/json-1.8.3 for inspection.
Results logged to /home/foobar/.rvm/gems/ruby-2.4.7/extensions/x86_64-linux/2.2.0/json-1.8.3/gem_make.out
As you can see, this is the complete code for the collect2 error inside your program. There is certainly something you can do to the syntax to debug this error and make the program functional again. Indeed, we are going to change some things in the library and this is going to completely remove the error. Take a look at the following section of this article to learn more.
– Using the Debugging Library Syntax for the collect2 Error
As previously explained, you are supposed to change certain things inside the library to fix this error. For this, you are going to need the gmp function to locate the correct files and return the incorrect status. Open the code with the cache search gmp function and include all the additional tools inside.
The following syntax shows how to properly use the gmp function to fix this error:
$ apt-cache search gmp
libgmp-dev – Multiprecision arithmetic library developers tools
libgmp10 – Multiprecision arithmetic library
libgmp10-doc – Multiprecision arithmetic library example code
libgmp3-dev – Multiprecision arithmetic library developers tools
libgmpxx4ldbl – Multiprecision arithmetic library (C++ bindings)
[…]
Be aware that the syntax may be subject to changes. As this example shows, the annoying collect2 error does not have to be complicated to locate and fix. However, pay attention to the exact location of the gmp function because this may sometimes be the difference between a correctly and incorrectly executed code. Let us now learn other things about this common error in your program.
– Facing This Error in Dev C++
As previously explained, the collect2 error may usually appear once working with Dev C++. It refers to a specific reference to a name where the linker cannot define the way it looks based on the object files. This also applies to all the libraries that make up your document.
Lucky for you, fixing the error is done in the same manner as previously taught. All you have to do is to follow the steps discussed in this article and the problem is going to disappear. To learn more about this error, continue reading the FAQ section of this article.
FAQs
Here are the answers to some of your questions regarding this error.
– What Is collect2 Exe?
Collect2 represents a utility that web developers use to arrange certain initialization functions during the start time. In other words, it is used to link the program and the adequate functions, while creating a table inside a temporary file. Then, it is going to create a second link with the program but include a different file.
– What Does Error 1d Returned 1 Exit Status Mean?
The returned 1 status refers to an error in your document that is created due to previous errors. It is used as an indicator to point out that certain linking steps during the building process have bugs. To fix the error, you are supposed to refer to all the previous functions and locate the part of the program that is operating incorrectly.
– How To Combine Two Files in C++?
You can start combining two files in C++ by creating two separate source files on your server. The process of combining two C++ files is important because you can combine two different programs and functions. Since the collect2 error usually appears during this process, it is important to understand how the files are merged together.
There are several steps you are supposed to closely follow, as shown in the following list:
- Create two separate C++ source files on your server.
- Both files should be saved inside the same location on the server.
- Open the Command Prompt tool and run the various commands from your files.
- The tool is going to merge the two separate source files together and comply their functions.
- Install the C++ Complier Program to run the newly-created file without any bugs.
This is all it takes to create a complex C++ file without facing any collect2 errors in your server. You can use this method for any two C++ files.
This section wraps everything important you were supposed to know about the collect2 error in your document. Let us now summarize the details.
Final Conclusion and Further Notes
This specific exit status error message is easily fixed by removing an existing executable file inside your document. Let us take a deep dive at the following list that contains all the important details from this article:
- The collect2 error is easily fixed by shutting down a program that is running in the background
- Web developers usually face this problem once working with Dev C++ and other files
- The Gem native extension usually displays this error alongside the complete syntax but it can be easily fixed
- It is important to know the meaning of collect2 to debug the error more efficiently
- It is possible to merge two C++ source files in five basic steps without caring about this error

- Author
- Recent Posts
Position Is Everything: Your Go-To Resource for Learn & Build: CSS,JavaScript,HTML,PHP,C++ and MYSQL.
|
Created attachment 45192 [details]
test case to reproduce the the failure
When attempt to build a simple code including one assembly file and one c code file while calling a c function from the assembly code and using the lto in linkage stage I encountered an error in the lto-wrapper where ld returned 1 exit status, with file not recognized: file truncated.
the build has been done in windows machine.
the toolchain used: gcc-arm-8.2-2018.08-i686-mingw32-arm-eabi
download link: https://developer.arm.com/-/media/Files/downloads/gnu-a/8.2-2018.08/gcc-arm-8.2-2018.08-i686-mingw32-arm-eabi.tar.xz?revision=37b1357c-06a5-4721-8fde-533b0028c083&la=en
gcc build info:
Using built-in specs.
COLLECT_GCC=..gcc-arm-8.2binarm-eabi-gcc.exe
COLLECT_LTO_WRAPPER=c:/tmp/gcc-arm-8.2/bin/../libexec/gcc/arm-eabi/8.2.1/lto-wrapper.exe
Target: arm-eabi
Configured with: /tmp/dgboter/bbs/dsggnu-vm-1-x86_64--mingw32-i686/buildbot/mingw32-i686--arm-eabi/build/src/gcc/configure --target=arm-eabi --prefix=/tmp/dgboter/bbs/dsggnu-vm-1-x86_64--mingw32-i686/buildbot/mingw32-i686--arm-eabi/build/build-mingw-arm-eabi/install// --with-gmp=/tmp/dgboter/bbs/dsggnu-vm-1-x86_64--mingw32-i686/buildbot/mingw32-i686--arm-eabi/build/build-mingw-arm-eabi/host-tools --with-mpfr=/tmp/dgboter/bbs/dsggnu-vm-1-x86_64--mingw32-i686/buildbot/mingw32-i686--arm-eabi/build/build-mingw-arm-eabi/host-tools --with-mpc=/tmp/dgboter/bbs/dsggnu-vm-1-x86_64--mingw32-i686/buildbot/mingw32-i686--arm-eabi/build/build-mingw-arm-eabi/host-tools --with-isl=/tmp/dgboter/bbs/dsggnu-vm-1-x86_64--mingw32-i686/buildbot/mingw32-i686--arm-eabi/build/build-mingw-arm-eabi/host-tools --with-pkgversion='GNU Toolchain for the A-profile Architecture 8.2-2018-08 (arm-rel-8.23)' --disable-shared --disable-nls --disable-threads --disable-tls --enable-checking=release --enable-languages=c,c++,fortran --with-newlib --with-multilib-list=aprofile --with-libiconv-prefix=/tmp/dgboter/bbs/dsggnu-vm-1-x86_64--mingw32-i686/buildbot/mingw32-i686--arm-eabi/build/build-mingw-arm-eabi/host-tools --host=i686-w64-mingw32
Thread model: single
gcc version 8.2.1 20180802 (GNU Toolchain for the A-profile Architecture 8.2-2018-08 (arm-rel-8.23))
Attached a simple test case [lto_test_arm.zip] that reproduce the failure.
I bet someone forgot to open a file as binary. I also suspect this has been fixed already.
I've reproduced this problem with a RISC-V gcc-8.x compiler, and tracked it down to the first patch for bug 81968, in comment #60. With the patch reverted, the testcase works. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81968#c60 The RISC-V testcase works with Linux hosted and Cygwin hosted toolchains, and only fails for mingw32 hosted toolchains. Maybe an LLP64 problem with the patch? I didn't see any obvious type error in the patch though. I had to borrow a windows machine from our IT group to look at this, and they have since taken the loaner back, so I don't have a machine at work I can use to debug this at present.
The question would be what (simple-object-common.h) the following resolves to:
/* Define ulong_type as an unsigned 64-bit type if available.
Otherwise just make it unsigned long. */
#ifdef UNSIGNED_64BIT_TYPE
__extension__ typedef UNSIGNED_64BIT_TYPE ulong_type;
#else
typedef unsigned long ulong_type;
#endif
it is tested by configure:
# Look for a 64-bit type.
AC_MSG_CHECKING([for a 64-bit type])
AC_CACHE_VAL(liberty_cv_uint64,
[AC_TRY_COMPILE(
[#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif],
[extern uint64_t foo;],
liberty_cv_uint64=uint64_t,
[AC_TRY_COMPILE(
[#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif],
[extern char foo[sizeof(long) * CHAR_BIT >= 64 ? 1 : -1];],
liberty_cv_uint64="unsigned long",
[AC_TRY_COMPILE(
[#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif
#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif],
[extern char foo[sizeof(long long) * CHAR_BIT >= 64 ? 1 : -1];],
liberty_cv_uint64="unsigned long long", liberty_cv_uint64=none)])])])
AC_MSG_RESULT($liberty_cv_uint64)
if test "$liberty_cv_uint64" != none; then
AC_DEFINE_UNQUOTED(UNSIGNED_64BIT_TYPE, $liberty_cv_uint64,
[Define to an unsigned 64-bit type available in the compiler.])
fi
the fallback for using unsigned long should probably be #error instead.
Not sure if we actually need this given arm-eabi should be ELF32?
I used a cross compiler, so ulong_type is easy enough to check. For simple-object-elf.i I see __extension__ typedef unsigned long long uint64_t; ... __extension__ typedef uint64_t ulong_type; which looks right.
i've used the RV gcc official toolchain and reverted the patch as Jim did. and it passed in the test case, but when i moved to a bigger code, i failed again to build. and it turned out that it passed only if i drop the -g option from the compiling command. when using the -g option it will get the "file not recognized: file format not recognized" again. i've downloaded the RV toolchain from: https://github.com/riscv/riscv-gnu-toolchain configuration for linux building: ./configure --with-arch=rv64imafdc --with-abi=lp64d --enable-multilib --prefix=<Path-to-build-output> configuration for windows building: ./configure --with-arch=rv64imafdc --with-abi=lp64d --enable-multilib --without-system-zlib --with-cmodel=medany --with-host=x86_64-w64-mingw32 --prefix=<Path-to-win-build> test case can be found at: https://github.com/westerndigitalcorporation/riscv32-Code-density-test-bench/tree/master/lto_test_case
Andrew Pinski is right, after chasing this bug with the help of Andrew Burgess
in the file simple-object.c, calling the creat
outfd = creat (dest, 00777);
the creat function wraps the open function but do not pass open mode
and the fix mentioned by Adrew was as follow:
When opening output files for simple-object creation, we must ensure that the file is opened in binary mode. Failure to do so causes file corruption, and LTO failure on Windows targets.
libiberty/ChangeLog:
PR lto/88422
* simple-object.c (O_BINARY): Define if not already defined.
(simple_object_copy_lto_debug_sections): Create file in binary
mode.
---
libiberty/ChangeLog | 7 +++++++
libiberty/simple-object.c | 6 +++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/libiberty/simple-object.c b/libiberty/simple-object.c index c1f38cee8ee..e061073abd1 100644
--- a/libiberty/simple-object.c
+++ b/libiberty/simple-object.c
@@ -44,6 +44,10 @@ Boston, MA 02110-1301, USA. */ #define SEEK_SET 0 #endif
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
#include "simple-object-common.h"
/* The known object file formats. */
@@ -349,7 +353,7 @@ simple_object_copy_lto_debug_sections (simple_object_read *sobj,
return errmsg;
}
- outfd = creat (dest, 00777);
+ outfd = open (dest, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY, 00777);
if (outfd == -1)
{
*err = errno;
--
Thanks for catching this! I'll apply the patch.
Fixed.
*** Bug 89183 has been marked as a duplicate of this bug. *** |

