Closed kimanha closed 5 years ago
Same comments as for issue #3: you've somehow unset CROSS_COMPILE
, and please don't build as root. Building PandA doesn't require root at any stage, and it must be built with the Xilinx cross-compile toolchain.
Okay, instead of ARM Debian local compile, I move to cross-compile from Linux Host computer. make server is a success. Thank you.
It looks like you're retargeting PandA to a different hardware and software platform? Is this right?
If so I guess you're going to encounter some compiler issues if you change compiler. The particular error you have encountered here comes from line 150 (and line 154) of server/Makefile
, and it looks as if your native compiler is treating const
initialised data differently from ours. Both our native (gcc 4.8.5) and cross (4.9.1) compilers place shared const
data in what nm
refers to as "a read only data section"; on the other hand, it looks as if your microjed compiler places this data in "the initialized data section".
I have tried more recent versions of gcc and have not seen this problem before. You can work around the problem simply by deleting the nm
lines, but I would like to know why this is happening.
Can you let me know what gcc --version
reports on your ARM Debian? Have you made any changes to CFLAGS
?
kha@microjed-sG:~/PandA/PandABlocks-server$ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/6/lto-wrapper Target: arm-linux-gnueabihf Configured with: ../src/configure -v --with-pkgversion='Debian 6.3.0-18+deb9u1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-armhf/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-armhf --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-armhf --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf Thread model: posix gcc version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)
I changed Makefile below:
BINUTILS_DIR =
KERNEL_DIR = /lib/modules/4.19.0-xilinx-v2019.1/build
PANDA_ROOTFS = /home/kha/PandA/PandABlocks-rootfs
Hmm. Can you show me the result of running this, please:
echo 'const int x = 1;' | gcc -x c -c -o test.o -; nm test.o
I get
0000000000000000 R x
but I'm guessing you'll get 00000000 D x
instead, and its the D
that's puzzling me.
Your compiler looks pretty new; I'll compare with Fedora when I have a chance.
my test platform is before move to picozed platform( I do not have picozed board).
Avnet microzed 7020 Kernel 4.19 Debian 9.0 rootfs
How can I get an FPGA design_xxx.hdf file? I tried to build FPGA project, but unfortunately, I can not build a project because of the environment is different. If you give me the latest hdf and device tree file then I can create petalinux kernel for the picozed SoC board.
Do you have Vivado FPGA project with a full module (Actually I send email to Uzun but no responded)?
Thanks,
@microjed-sG:~/PandA/PandABlocks-server$ echo 'const int x = 1;' | gcc -x c -c -o test.o -; nm test.o 00000000 R x
Interesting. I wonder why you got D
for the declarations in the server. If you could experiment on one of the source files I'd be grateful: maybe it's a compiler option, maybe it's something in the source. All the names (focus on just one, say entity_commands
which you can find in server/config_command.c
) are declared as const
structures with a separate extern
declaration, and they should all go into R
blocks.
For FPGA build questions, I suggest you put an issue on PandABlocks-FPGA.
are declared as const structures with a separate extern declaration, and they should all go into R blocks.
Can you please give some example how change code for test?
Sure. It's a bit of a drawn out process, but here goes.
First of all, let's get the build command and verify that we're chasing the right problem. Go back to your ARM Debian system and run make server
, check that we get the error again. To find the precise build command, run touch server/config_command.c
, run make server
, and look for a very long line starting gcc
and ending /path/to/server/config_command.c
; on my system I get:
arm-xilinx-linux-gnueabi-gcc -std=gnu99 -O3 -g -Werror -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wcast-qual -Woverflow -Wconversion -fstrict-overflow -Wsign-compare -Wstrict-overflow=5 -Wno-switch-enum -Wno-variadic-macros -Wno-padded -Wno-format-nonliteral -Wno-vla -Wno-c++-compat -Wno-pointer-arith -Wno-unused-parameter -Wno-missing-field-initializers -D_GNU_SOURCE -I/home/mga83/targetOS/zebra2-server/driver -I. -c -o config_command.o /home/mga83/targetOS/zebra2-server/server/config_command.c
Please paste a copy of your version of this command here!
You can now run this command anywhere to rebuild config_command.o
, and check for the problem by running
nm config_command.o | grep entity_commands
If this returns a line with R
the problem has gone away, and I'm out of ideas, if there is a D
we are in business.
I'd then start by pruning all the -W
options from the gcc
command line, and you can safely prune the -I
options; my command line reduces to:
arm-xilinx-linux-gnueabi-gcc -std=gnu99 -O3 -g -D_GNU_SOURCE -c -o config_command.o /home/mga83/targetOS/zebra2-server/server/config_command.c
Run nm
and check for D
or R
again. Next you can try removing the -O3
, -g
, -D_GNU_SOURCE
options, rerun, check again. If you're down to something as simple as gcc -std=gnu99 -c -o config_command.o config_command.c
and still generating D
then it's something to do with the source.
Take a copy of config_command.c
(and make sure your new simplified gcc
command now points to it). First of all I'd delete lines 341-343 (the .get
, .put
, .put_table
assignments in the entity_commands
definition), rebuild, see if we have D
or R
. If still D
then you can delete everything in config_command.c
from the last #include
up to the definition of entity_commands
(lines 18-339) and try again.
If we're still getting D
... well, let's see how you get on.
P.S. The nm
test can safely be deleted from your build, it's just me trying to make sure I don't accidentally create any writeable global variables. However, I'd rather get to the bottom of this if you have the patience...
gcc -M -D_GNU_SOURCE -I/home/kha/PandA/PandABlocks-server/driver -I. -std=gnu99 -O3 -g -Werror -Wall -Wextra -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wredundant-decls -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wcast-qual -Woverflow -Wconversion -fstrict-overflow -Wsign-compare -Wstrict-overflow=5 -Wno-switch-enum -Wno-variadic-macros -Wno-padded -Wno-format-nonliteral -Wno-vla -Wno-c++-compat -Wno-pointer-arith -Wno-unused-parameter -Wno-missing-field-initializers /home/kha/PandA/PandABlocks-server/server/config_command.c
~/PandA/PandABlocks-server/server$ gcc -std=gnu99 -c -o config_command.o config_command.c
kha@microjed-sG:~/PandA/PandABlocks-server/server$ nm config_command.o | grep entity_commands
00000030 D entity_commands
First of all I'd delete lines 341-343 (the .get, .put, .put_table assignments in the entity_commands definition), rebuild
nm config_command.o | grep entity_commands
00000080 R entity_commands
Thank you, that is helpful and interesting, and you've verified that the issue is in the content of the C file.
I'm going to guess that the difference between the two cases is the presence of links to functions in the C code. Can you try again with the following minimal case. Create a file test.c
with the following two lines:
static int f(int x) { return x; }
const struct { int (*f)(int); } s = { .f = f };
Compile this with the following command:
gcc -c -o -O2 test.o test.c
and look at the result with nm
:
$ nm test.o
00000000 t $a
U __aeabi_unwind_cpp_pr0
00000000 r $d
00000000 r $d
00000000 t f
00000000 R s
(That's what I see with our Xilinx compiler, I see a slightly simpler output with native gcc.)
If you see 00000000 D s
then we've verified the problem, and I'll have to ask elsewhere about this strange compiler behaviour. If you do see this, also can you run:
gcc -c -S -O2 test.c
and paste the contents of test.s
here.
kha@microjed-sG:~/test$ gcc -c -o -O2 test.o test.c
gcc: error: test.o: No such file or directory
kha@microjed-sG:~/test$ gcc -c -O2 -o test.o test.c
kha@microjed-sG:~/test$ nm test.o
00000000 t f
00000000 D s
kha@microjed-sG:~/test$ gcc -c -S -O2 test.c
kha@microjed-sG:~/test$ cat test.s
.arch armv7-a
.eabi_attribute 28, 1
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 2
.eabi_attribute 34, 1
.eabi_attribute 18, 4
.file "test.c"
.text
.align 1
.p2align 2,,3
.syntax unified
.thumb
.thumb_func
.fpu vfpv3-d16
.type f, %function
f:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
bx lr
.size f, .-f
.global s
.section .data.rel.ro.local,"aw",%progbits
.align 2
.type s, %object
.size s, 4
s:
.word f
.ident "GCC: (Debian 6.3.0-18+deb9u1) 6.3.0 20170516"
.section .note.GNU-stack,"",%progbits
Sorry, I messed up the -O2
flag! I guess I need one more piece to complete the story. So here we see variable s
going into section .data.rel.ro.local
, presumably because it's got a link (to f
) that will need relocation. Can you extend test.c
with one more line, please:
static int f(int x) { return x; }
const struct { int (*f)(int); } s = { .f = f };
const int t = 0;
and try again: it's probably enough to just tell me what section t
goes into (I'm presuming t
will be a R
symbol).
I doubt I'll get much further with this, you'll have to work around this (just remove the nm
line from the build) if you want native compilation, but I think you've given me all the information I need if only I can figure out who to ask about this...
So, it seems that the .data.rel.ro.local
section is a linker trick: gcc SO question linking to Linker relro. Alas, it looks as if nm
reports this section as D
not R
.
I'm going to say we're stuck with this behaviour with your complier and close this out. Still, I would be grateful if you do add the section info for t
in my last comment.
kha@microjed-sG:~/PandA/PandABlocks-server$ nm test1.o
00000000 t f
00000000 D s
00000000 R t
kha@microjed-sG:~/PandA/PandABlocks-server$ cat test1.s
.arch armv7-a
.eabi_attribute 28, 1
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 2
.eabi_attribute 34, 1
.eabi_attribute 18, 4
.file "test1.c"
.text
.align 1
.p2align 2,,3
.syntax unified
.thumb
.thumb_func
.fpu vfpv3-d16
.type f, %function
f:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
bx lr
.size f, .-f
.global t
.global s
.section .rodata
.align 2
.type t, %object
.size t, 4
t:
.space 4
.section .data.rel.ro.local,"aw",%progbits
.align 2
.type s, %object
.size s, 4
s:
.word f
.ident "GCC: (Debian 6.3.0-18+deb9u1) 6.3.0 20170516"
.section .note.GNU-stack,"",%progbits
you'll have to work around this (just remove the nm line from the build) if you want native compilation
without nm it compiled.
Ta. That is, alas, exactly as expected. Guess I'll have to ask on a suitable gcc forum.
Hmm. I'm seeing the same behaviour on Ubuntu (gcc version 7.4.0); am pretty sure I tested on Fedora which is gcc 8 something, and RHEL7 (gcc 4.8.5) without the problem.
Thank you for your help. For now I'm inclined to put this down to a gcc version issue, but I'll leave this issue closed for the time being.
Thank so much for your support.
I have Debian 7 and old kernel version. Can you please look at any difference?
zbpm:~/test# uname -r
3.17.0-xilinx
zbpm:~/test# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.3-14' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 4.6.3 (Debian 4.6.3-14)
zbpm:~/test# cat test1.c
static int f(int x) { return x; }
const struct { int (*f)(int); } s = { .f = f };
const int t = 0;
zbpm:~/test# gcc -c -O2 -o test1.o test1.c
zbpm:~/test# ls
test1.c test1.o
zbpm:~/test# nm test1.o
00000000 t f
00000004 R s
00000000 R t
zbpm:~/test# cat test1.s
.syntax unified
.arch armv7-a
.eabi_attribute 27, 3
.eabi_attribute 28, 1
.fpu vfpv3-d16
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 2
.eabi_attribute 18, 4
.thumb
.file "test1.c"
.text
.align 2
.thumb
.thumb_func
.type f, %function
f:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
bx lr
.size f, .-f
.global t
.global s
.section .rodata
.align 2
.type t, %object
.size t, 4
t:
.space 4
.type s, %object
.size s, 4
s:
.word f
.ident "GCC: (Debian 4.6.3-14) 4.6.3"
.section .note.GNU-stack,"",%progbits
I'll try and draw up a table of what we've learnt:
GCC | Dist | nm |
section |
---|---|---|---|
4.6.3 | Debian 7 | R |
.rodata |
4.8.5 | RHEL7 | R |
.rodata |
6.3.0 | Debian 9 | D |
.data.rel.ro.local |
7.4.0 | Ubuntu 18.04 | D |
.data.rel.ro.local |
9.1.1 | Fedora 30 | R |
.rodata |
So the nm
problem is directly correlated with using .data.rel.ro.local
, which seems to be a Debian issue.
By the way, we can simplify the test code to the following two lines:
const int t = 0;
const int *const u = &t;
It's the presence of a relocation that's making the difference.
Debian 7:
nm test2.o
00000004 R t
00000000 R u
zbpm:~/test# cat test2.s
.syntax unified
.arch armv7-a
.eabi_attribute 27, 3
.eabi_attribute 28, 1
.fpu vfpv3-d16
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 2
.eabi_attribute 18, 4
.thumb
.file "test2.c"
.global u
.global t
.section .rodata
.align 2
.type u, %object
.size u, 4
u:
.word t
.type t, %object
.size t, 4
t:
.space 4
.ident "GCC: (Debian 4.6.3-14) 4.6.3"
.section .note.GNU-stack,"",%progbits
Debian 9:
kha@microjed-sG:~/test$ nm test2.o
00000000 R t
00000000 D u
drvHello test.c test.o test.s test2.c test2.s
kha@microjed-sG:~/test$ cat test2.s
.arch armv7-a
.eabi_attribute 28, 1
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 2
.eabi_attribute 30, 2
.eabi_attribute 34, 1
.eabi_attribute 18, 4
.file "test2.c"
.global u
.global t
.section .rodata
.align 2
.type t, %object
.size t, 4
t:
.space 4
.section .data.rel.ro.local,"aw",%progbits
.align 2
.type u, %object
.size u, 4
u:
.word t
.ident "GCC: (Debian 6.3.0-18+deb9u1) 6.3.0 20170516"
.section .note.GNU-stack,"",%progbits
Hello,
I am trying to local compile based on ARM Debian 9 and I found below error. Any way to compile source ?
Thanks, Kiman NSLS-II Controls