How is this gcc instruction being interpreted? - gcc

I downloaded libopencm3 (https://github.com/libopencm3/libopencm3) library and compiled it. It worked. I found a small project that uses this library and copied the instructions from its makefile.
all:
arm-none-eabi-gcc \
-Os \
-ggdb3 \
-mthumb \
-mcpu=cortex-m0 \
-msoft-float \
-Wall \
-Wextra \
-Wundef \
-Wshadow \
-Wredundant-decls \
-fno-common \
-ffunction-sections \
-fdata-sections \
-std=c11 \
-MD \
-DSTM32F0 \
-I./libopencm3/include \
-o main.o \
-c main.c
arm-none-eabi-gcc \
--static \
-nostartfiles \
-Tstm32f0.ld \
-mthumb \
-mcpu=cortex-m0 \
-msoft-float \
-ggdb3 \
-Wl,-Map=main.map \
-Wl,--cref \
-Wl,--gc-sections \
-L./libopencm3/lib \
main.o \
-lopencm3_stm32f0 \
-Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group \
-o main.elf
I created a folder for the project, pasted libopencm3 folder inside it and compiled. It's working, but I don't understand how this part works:
-L./libopencm3/lib main.o -lopencm3_stm32f0
If I am right, it is instructing to find opencm3_stm32f0 library inside /libopencm3/lib, but inside that folder I found libopencm3_stm32f0.a instead.
I want to know why they changed the name and omitted the extension and it still worked.

This isn't related to makefiles or to any specific library, or to embedded systems, so those tags on your question are not needed.
If you look up the -l option in the documentation of the linker, you'll understand how it works.

Related

Error when building gcc with --enable-host-shared and MIPS target

I am trying to build gcc with --enable-host-shared plus the jit backend in order to use it with the rustc gcc backend.
I tried with both gcc version 12.1.0 and 11.3.0.
Here is how I configure it:
$GCC/configure \
--prefix=$PREFIX \
--target="mips64r5900el-ps2-elf" \
--enable-languages=c,jit \
--enable-checking=release \
--enable-host-shared \
--disable-libssp \
--disable-multilib \
--disable-bootstrap \
--without-headers \
--with-float=hard
The build fails when reaching libgcc with the error:
/home/davide/Documents/Rust/ps2-rustc/build/ee/build-gcc/./gcc/xgcc -B/home/davide/Documents/Rust/ps2-rustc/build/ee/build-gcc/./gcc/ -B/home/davide/Documents/Rust/ps2-rustc/build/ee/install/mips64r5900el-ps2-elf/bin/ -B/home/davide/Documents/Rust/ps2-rustc/build/ee/install/mips64r5900el-ps2-elf/lib/ -isystem /home/davide/Documents/Rust/ps2-rustc/build/ee/install/mips64r5900el-ps2-elf/include -isystem /home/davide/Documents/Rust/ps2-rustc/build/ee/install/mips64r5900el-ps2-elf/sys-include -g -O2 -O2 -g -O2 -DIN_GCC -fPIC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -G 0 -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -Dinhibit_libc -G 0 -I. -I. -I../.././gcc -I/home/davide/Documents/Rust/ps2-rustc/build/ee/gcc-12.1.0/libgcc -I/home/davide/Documents/Rust/ps2-rustc/build/ee/gcc-12.1.0/libgcc/. -I/home/davide/Documents/Rust/ps2-rustc/build/ee/gcc-12.1.0/libgcc/../gcc -I/home/davide/Documents/Rust/ps2-rustc/build/ee/gcc-12.1.0/libgcc/../include -DHAVE_CC_TLS -o subsf3.o -MT subsf3.o -MD -MP -MF subsf3.dep -DFUNC=__subsf3 -DOP_sub3 -DTYPE=sf -c /home/davide/Documents/Rust/ps2-rustc/build/ee/gcc-12.1.0/libgcc/config/hardfp.c -fvisibility=hidden -DHIDE_EXPORTS -Wno-missing-prototypes
cc1: error: position-independent code requires ‘-mabicalls’
I tried to remove --enable-host-shared and everything compiles fine. The problem is that with the flag enabled, it forces gcc to compile libgcc with -fPIC, which according to this also requires -mabicalls which doesn't get passed.
My guess is that it is trying to build libgcc as a pic in order to dynamically link to it for the JIT functionality, but I will only use AOT functionality, so a static libgcc is totally fine.
Is there a quick way to fix this? And should this be reported as a bug?
Thanks!

make/gcc/clang looking for file with a blank filename, gives error

I have OSX 10.11.4, Xcode 7.3.1.
Using make -- calls gcc -- calls clang, I get this error where clang is looking for a file whose name is a space!
Make error 1: clang: error: no such file or directory: ' '.
That is a space!
I have no idea how to fix this. The makefile formatting is correct.
Here is the end of the output from make:
gcc -g -v -Wall -I/usr/local/include -I/opt/local/include -I/Users/m/BioPrep \
-o mod \
../mshell/runit0.o \
../mshell/tline.o \
../mshell/getshm.o \
../mshell/callLSODA.o \
../mshell/extras.o \
../mshell/nrutil.o \
../mshell/exten.o \
../choosedisp/choosedisp_main.o \
../choosedisp/choosedisp_cb.o \
../choosedisp/choosedisp_fm.o \
../connectdisps/connectdisps.o \
../connectdisps/opwsock.o \
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
clang: error: no such file or directory: ' '
make: *** [mod] Error 1
======================= Here is the contents of the Makefile:
# This is Makefile with all graphics code removed so that a compilation of mod can proceed
# "MakefileA" has the graphics files present but commented (#) out
CC = gcc
CFLAGS = -g -v -Wall
INCL = -I/usr/local/include -I/opt/local/include -I/Users/prowat/BioPrep
LIBS = -L/usr/local/lib -L/opt/local/lib -lX11 -lforms
mod: model.o \
../mshell/runit0.o \
../mshell/tline.o \
../mshell/getshm.o \
../mshell/callLSODA.o \
../mshell/extras.o \
../mshell/nrutil.o \
../mshell/exten.o \
../choosedisp/choosedisp_main.o \
../choosedisp/choosedisp_cb.o \
../choosedisp/choosedisp_fm.o \
../connectdisps/connectdisps.o \
../connectdisps/opwsock.o \
../lsoda/liblsoda.a`
cd ../mshell; make objs`
cd ../choosedisp; make objs`
cd ../connectdisps; make objs`
$(CC) $(CFLAGS) $(INCL) \
-o mod \
../mshell/runit0.o \
../mshell/tline.o \
../mshell/getshm.o \
../mshell/callLSODA.o \
../mshell/extras.o \
../mshell/nrutil.o \
../mshell/exten.o \
../choosedisp/choosedisp_main.o \
../choosedisp/choosedisp_cb.o \
../choosedisp/choosedisp_fm.o \
../connectdisps/connectdisps.o \
../connectdisps/opwsock.o \
model.o \
-L../lsoda -llsoda \
$(LIBS) \
-lm
=====================
Please use proper formatting: for code blocks, indent by 4 spaces. The backticks are only used for fixed-width fonts inside normal text.
You may have looked for spaces, but you need to look again. Based on the output make has shown you versus your makefile, it's pretty clear that there is at least one space after the backslash at the end of this line:
../connectdisps/opwsock.o \
You can tell this because if there were no spaces after this backslash then it would be continuing to the next line and make whould show the rest of the compile line:
model.o \
-L../lsoda -llsoda \
$(LIBS) \
-lm
Since those lines are missing from the output make provided, you can be sure that there's something about the opwsock.o line which is preventing make from recognizing the backslash/newline at the end.

GNU make is adding an extra step not in my Makefile that causes all sorts of linker errors. What's going on?

Given the following makefile for GNU make:
# TODOs so I don't forget:
# - make debugging an option
# - make 64 below an actual option
# - figure out why make test seems to rebuild the DLL
# - __declspec(dllimport)
ifeq ($(MAKECMDGOALS),64)
CC = x86_64-w64-mingw32-gcc
RC = x86_64-w64-mingw32-windres
mflag = -m64
else
CC = i686-w64-mingw32-gcc
RC = i686-w64-mingw32-windres
mflag = -m32
endif
OBJDIR = .objs
OUTDIR = out
BASENAME = wintable
DLLFILE = $(OUTDIR)/$(BASENAME).dll
LIBFILE = $(OUTDIR)/$(BASENAME).lib
TESTEXEFILE = $(OUTDIR)/$(BASENAME).exe
CFILES = \
alloc.c \
api.c \
checkboxdraw.c \
checkboxevents.c \
children.c \
coord.c \
debug.c \
draw.c \
events.c \
header.c \
hscroll.c \
main.c \
metrics.c \
modelhelpers.c \
nullmodel.c \
resize.c \
scroll.c \
select.c \
update.c \
util.c \
visibility.c \
vscroll.c
HFILES = \
table.h \
tablepriv.h
TESTCFILES = \
test.c
OFILES = $(CFILES:%.c=$(OBJDIR)/%.o)
TESTOFILES = $(TESTCFILES:%.c=$(OBJDIR)/%.o)
xCFLAGS = \
--std=c99 \
-Wall \
-Wextra \
-Wno-unused-parameter \
$(mflag) \
$(CFLAGS)
xLDFLAGS = \
-static-libgcc \
-luser32 -lkernel32 -lgdi32 -lcomctl32 -luxtheme -lole32 -loleaut32 -loleacc -luuid -lmsimg32 \
$(mflag) \
$(LDFLAGS)
default:
$(MAKE) clean
$(MAKE) it
$(MAKE) test
it: $(DLLFILE)
$(DLLFILE): $(OFILES)
$(CC) -g -o $(DLLFILE) -shared -Wl,--out-implib,$(LIBFILE) $(OFILES) $(xLDFLAGS)
test: $(TESTEXEFILE)
$(TESTEXEFILE): $(DLLFILE) $(TESTOFILES)
$(CC) -g -o $(TESTEXEFILE) $(TESTOFILES) $(LIBFILE) $(xLDFLAGS)
$(OBJDIR)/%.o: %.c $(HFILES) dirs
$(CC) -g -o $# -c $< $(xCFLAGS)
dirs:
mkdir -p $(OBJDIR) $(OUTDIR)
clean:
rm -rf $(OBJDIR) $(OUTDIR)
make -n test produces
mkdir -p .objs out
i686-w64-mingw32-gcc -g -o .objs/alloc.o -c alloc.c --std=c99 -Wall -Wextra -Wno-unused-parameter -m32
i686-w64-mingw32-gcc -g -o .objs/api.o -c api.c --std=c99 -Wall -Wextra -Wno-unused-parameter -m32
(and so on for all the other C files)
i686-w64-mingw32-gcc -g -o out/wintable.dll -shared -Wl,--out-implib,out/wintable.lib .objs/alloc.o .objs/api.o .objs/checkboxdraw.o .objs/checkboxevents.o .objs/children.o .objs/coord.o .objs/debug.o .objs/draw.o .objs/events.o .objs/header.o .objs/hscroll.o .objs/main.o .objs/metrics.o .objs/modelhelpers.o .objs/nullmodel.o .objs/resize.o .objs/scroll.o .objs/select.o .objs/update.o .objs/util.o .objs/visibility.o .objs/vscroll.o -static-libgcc -luser32 -lkernel32 -lgdi32 -lcomctl32 -luxtheme -lole32 -loleaut32 -loleacc -luuid -lmsimg32 -m32
i686-w64-mingw32-gcc -g -o .objs/test.o -c test.c --std=c99 -Wall -Wextra -Wno-unused-parameter -m32
i686-w64-mingw32-gcc -g -o out/wintable.exe .objs/test.o out/wintable.lib -static-libgcc -luser32 -lkernel32 -lgdi32 -lcomctl32 -luxtheme -lole32 -loleaut32 -loleacc -luuid -lmsimg32 -m32
i686-w64-mingw32-gcc test.c out/wintable.exe -o test
Notice how the last step that GNU make decides to do tries to recompile my test.c with the correct output executable file built before that into a new test executable, which (predictably) fails spectacularly:
out/wintable.exe: In function `WinMainCRTStartup':
/build/buildd/mingw-w64-3.1.0/build/i686-w64-mingw32-i686-w64-mingw32-crt/../../mingw-w64-crt/crt/crtexe.c:171: multiple definition of `WinMainCRTStartup'
/usr/lib/gcc/i686-w64-mingw32/4.9-win32/../../../../i686-w64-mingw32/lib/../lib/crt2.o:/build/buildd/mingw-w64-3.1.0/build/i686-w64-mingw32-i686-w64-mingw32-crt/../../mingw-w64-crt/crt/crtexe.c:171: first defined here
out/wintable.exe: In function `mainCRTStartup':
/build/buildd/mingw-w64-3.1.0/build/i686-w64-mingw32-i686-w64-mingw32-crt/../../mingw-w64-crt/crt/crtexe.c:199: multiple definition of `mainCRTStartup'
/usr/lib/gcc/i686-w64-mingw32/4.9-win32/../../../../i686-w64-mingw32/lib/../lib/crt2.o:/build/buildd/mingw-w64-3.1.0/build/i686-w64-mingw32-i686-w64-mingw32-crt/../../mingw-w64-crt/crt/crtexe.c:199: first defined here
out/wintable.exe:cygming-crtbegin.c:(.text+0x500): multiple definition of `__gcc_register_frame'
/usr/lib/gcc/i686-w64-mingw32/4.9-win32/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here
out/wintable.exe:cygming-crtbegin.c:(.text+0x550): multiple definition of `__gcc_deregister_frame'
/usr/lib/gcc/i686-w64-mingw32/4.9-win32/crtbegin.o:cygming-crtbegin.c:(.text+0x50): first defined here
out/wintable.exe: In function `mainwinCreate':
/home/pietro/src/github.com/andlabs/wintable/test.c:20: multiple definition of `mainwinCreate'
/tmp/cc50VrIz.o:test.c:(.text+0x0): first defined here
out/wintable.exe: In function `mainwinDestroy':
/home/pietro/src/github.com/andlabs/wintable/test.c:66: multiple definition of `mainwinDestroy'
/tmp/cc50VrIz.o:test.c:(.text+0x2ba): first defined here
(and so on for virtually every symbol in my test.c)
/usr/lib/gcc/i686-w64-mingw32/4.9-win32/crtbegin.o:cygming-crtbegin.c:(.text+0x22): undefined reference to `_Jv_RegisterClasses'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'test' failed
make: *** [test] Error 1
Where is this last step coming from? It's nowhere in my makefile, as far as I can tell. (Notice the lack of compiler flags.) Googling the problem was also ineffective here. This only started to happen today, with all the same rules as before (the only change is the addition of modelhelpers.c and nullmodel.c to CFILES), so I'm not sure what's going on.
Does it have to do with the rule being test? If so, why did it work before?
This is GNU make 4.0 on Ubuntu GNOME 14.10.
Thanks.
Make has various built-in implicit rules, and one of them is the pattern rule % : %.c, which tells make how to create an executable (in UNIX systems, executables don't have any extension like .exe etc., they're just words like test, mkdir, etc.) if it has a source file with the same extension.
Your makefile has:
test: $(TESTEXEFILE)
and you provide no recipe for building the target test, so make looks at its built-in rules and finds % : %.c, and then make looks and sees that you DO have a test.c file, so make applies that default recipe to build the target test, which you asked it to do.
If you don't want this to happen you should tell make that test is not a real target: that you're only using it as a handle to build other things, using the .PHONY special target:
.PHONY: test
From the manual:
The implicit rule search is skipped for .PHONY targets.

Performance loss with gcc linker optimization flag -flto

I am working on a ARM Cortex A15 and using GCC compile (actually integrating it with TI's SYS/BIOS using XDC tools...)
After I enable -ftlo flag, I am having a performance loss about %30, which is a significant value. I am doing simple benchmark tests like pi and prime number calculating and also system dependent procedural tests.
Below are my compile and link flags. Is this amount of downgrade possible without any errors? Is there a possible cause for this? From what I searched through the internet, I come across benchmarks that flto may not improve the performance but I didn't see such a performance loss...
# Compile options.
C_OPTS = -w\
-mcpu=cortex-a15 \
-mtune=cortex-a15 \
-mabi=aapcs \
-mapcs \
-mfpu=neon \
-mfloat-abi=hard \
-O3 \
-flto \
-fno-strict-aliasing \
-fno-delete-null-pointer-checks \
-fno-strict-overflow \
# Linker options.
L_OPTS = -nostartfiles \
-static \
-Wl,--gc-sections \
-Wl,-Map,$(BUILD_DIR)/$(NAME).map \
-mfloat-abi=hard \
-e wbcd_ep \
-flto \
-fuse-linker-plugin \

Include path being ignored in a gnu make file

The makefile is included below. It's just a long list of object files and two targets. The problem seems to be that the $(INC) is being ignored for the first target. For example, the output starts with "g++ -c -o main.o main.cpp" instead of "g++ -I/usr/home/jrm/tmp/proteus_beta -c -o main.o main.cpp".
TIA
PROG = proteus
# list of object files
OBJS = main.o \
dataset.o \
genetic_codes.o \
likelihood_engine.o \
options.o \
parsimony.o \
parsimony_engine.o \
seq.o \
site_collection.o \
site_pattern.o \
tools.o \
optare/crs.o \
optare/point.o \
optare/newton_1d.o \
optare/golden_section.o \
models/model.o \
models/DNA/DNA_model.o \
models/DNA/DNA_ssm.o \
models/CODON/CODON_model.o \
models/CODON/CODON_modelA.o \
models/CODON/CODON_modelB.o \
models/CODON/CODON_modelC.o \
models/CODON/CODON_modelD.o \
models/CODON/CODON_M0.o \
models/CODON/CODON_M1.o \
models/CODON/CODON_M2.o \
models/CODON/CODON_M3.o \
models/CODON/CODON_M0gtr.o \
models/CODON/CODON_FEBC1.o \
models/CODON/CODON_FEBC1b.o \
models/CODON/FESC/CODON_FESC1.o \
models/CODON/CODON_nh/CODON_M0nh1.0 \
models/CODON/CODON_nh/CODON_M1nh1.0 \
models/CODON/CODON_nh/CODON_M1nh1.0 \
models/CODON/CODON_nh/CODON_M3nh1.0 \
models/CODON/CODON_nh/CODON_M0nh2.0 \
models/CODON/CODON_nh/CODON_MmodelAnh2.0 \
matrices/matrix.o \
matrices/DNA_matrix.o \
matrices/CODON_matrix.o \
matrices/AA_matrix.o \
matrices/int_matrix.o \
matrices/str_matrix.o \
matrices/eigen.o \
incidere/slice_sampler.o \
dendrology/forestry.o \
dendrology/node.o \
dendrology/DNA_node.o \
dendrology/tree.o \
alphabetia/alphabet.o \
alphabetia/DNA_alphabet.o \
alphabetia/CODON_alphabet.o \
alphabetia/AA_alphabet.o
CC = g++
INC=-I/home/jrm/tmp/proteus_beta
.C.o:
$(CC) $< -c $(INC)
$(PROG): $(OBJS)
$(CC) -o $# $(OBJS) -lm
According to your post, you have a file named main.cpp, not a file named main.C. But you provide an implicit rule for converting .C files to .o. Make will compile main.cpp using its built-in rule for .cpp to .o compilation. You have two options to do what you want:
(1) Change your implicit rule to .cpp.o (and consider using new-style rules, i.e. %.cpp: %.o)
(2) Declare a CXXFLAGS variable (which is automatically included in Make's C++ compilation implicit rule) such as the following:
CXXFLAGS = $(INC)
and then remove your .C.o implicit rule.
The second option will simplify your makefile, and it will work with C++ files, regardless of the extension.
Do your source files end with .C or .cpp?
The compilation rule for .C.o lists $(INC) after the other parts of the rule, not where you expect the output to come:
CC = g++
INC = -I/home/jrm/tmp/proteus_beta
.C.o:
$(CC) $< -c $(INC)
You should see:
g++ file.C -c -I/home/jrm/tmp/proteus_beta
But it appears to be ignoring your rule altogether. You mention main.cpp; that will never be compiled by your rule.
So, is .C a recognized suffix? Are your source files .C files? Are you running on a case-insensitive file-system? Why are you setting the C compiler (CC) -- you've probably got case problems with your source.

Resources