hippy
Posts: 6766
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

[Solved] Overcoming a GCC 'sudo' issue

Fri Feb 14, 2020 2:50 pm

I installed a pre-built compiler package for creating code for the ZyLin ZPU processor ...

Code: Select all

cd ~
mkdir zpugcc
cd zpugcc
wget ftp://ftp.embeddedarm.com/ts-arm-sbc/ts-7180-linux/zpu/armhf-zpu-elf-gcc-3.4.2.tar.bz2
bzip2 -dk armhf-zpu-elf-gcc-3.4.2.tar.bz2
tar -xvf armhf-zpu-elf-gcc-3.4.2.tar
That all works fine but when I create my C program, run the compiler, I get "Permission denied" errors and no assembler source code output ...

Code: Select all

[email protected]:~/zpugcc $ ./armhf-zpu-elf-gcc-3.4.2/bin/zpu-elf-gcc -S fibo.c
cc1: /root/Downloads/zpugcc/toolchain/install/lib/gcc/zpu-elf/3.4.2/include: Permission denied
cc1: /root/Downloads/zpugcc/toolchain/install/zpu-elf/sys-include: Permission denied
cc1: /root/Downloads/zpugcc/toolchain/install/zpu-elf/include: Permission denied
[email protected]:~/zpugcc $ ls -l fibo.*
-rw-r--r-- 1 pi pi 170 Feb 14 14:29 fibo.c
[email protected]:~/zpugcc $ 
If I run it with 'sudo' it works as expected and I get my assembler code, though that's then owned by root ...

Code: Select all

[email protected]:~/zpugcc $ sudo ./armhf-zpu-elf-gcc-3.4.2/bin/zpu-elf-gcc -S fibo.c
[email protected]:~/zpugcc $ ls -l fibo.*
-rw-r--r-- 1 pi   pi    170 Feb 14 14:29 fibo.c
-rw-r--r-- 1 root root 1303 Feb 14 14:30 fibo.s
[email protected]:~/zpugcc $ 
The issue seems to me to be that the compiler has been configured to use /root ...

Code: Select all

[email protected]:~/zpugcc $ sudo ./armhf-zpu-elf-gcc-3.4.2/bin/zpu-elf-gcc -v -S fibo.c
Reading specs from /home/pi/zpugcc/armhf-zpu-elf-gcc-3.4.2/bin/../lib/gcc/zpu-elf/3.4.2/specs
Configured with: ../gcc/configure --target=zpu-elf --prefix=/root/Downloads/zpugcc/toolchain/gccbuild/../install --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --with-newlib --disable-shared --enable-newlib -v --enable-checking=misc,tree,rtl,rtlflag,gc,gcac,fold --disable-multilib --disable-threads --enable-sjlj-exceptions --enable-libstdcxx-allocator=malloc
Thread model: single
gcc version 3.4.2
 /home/pi/zpugcc/armhf-zpu-elf-gcc-3.4.2/bin/../libexec/gcc/zpu-elf/3.4.2/cc1 -quiet -v -iprefix /home/pi/zpugcc/armhf-zpu-elf-gcc-3.4.2/bin/../lib/gcc/zpu-elf/3.4.2/ fibo.c -quiet -dumpbase fibo.c -auxbase fibo -version -o fibo.s
ignoring nonexistent directory "/home/pi/zpugcc/armhf-zpu-elf-gcc-3.4.2/bin/../lib/gcc/zpu-elf/3.4.2/../../../../zpu-elf/sys-include"
ignoring nonexistent directory "/root/Downloads/zpugcc/toolchain/install/lib/gcc/zpu-elf/3.4.2/include"
ignoring nonexistent directory "/root/Downloads/zpugcc/toolchain/install/zpu-elf/sys-include"
ignoring nonexistent directory "/root/Downloads/zpugcc/toolchain/install/zpu-elf/include"
#include "..." search starts here:
#include <...> search starts here:
 /home/pi/zpugcc/armhf-zpu-elf-gcc-3.4.2/bin/../lib/gcc/zpu-elf/3.4.2/include
 /home/pi/zpugcc/armhf-zpu-elf-gcc-3.4.2/bin/../lib/gcc/zpu-elf/3.4.2/../../../../zpu-elf/include
End of search list.
GNU C version 3.4.2 (zpu-elf)
        compiled by GNU C version 4.9.2.
GGC heuristics: --param ggc-min-expand=0 --param ggc-min-heapsize=0
I can get around the issue by using 'sudo' and 'chown', but I accept "that's not the way to do things".

Does anyone know how I resolve the issue so I don't have to do that ?
Last edited by hippy on Fri Feb 14, 2020 7:42 pm, edited 1 time in total.

User avatar
RaTTuS
Posts: 10531
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Overcoming a GCC 'sudo' issue

Fri Feb 14, 2020 2:58 pm

this :-
cc1: /root/Downloads/zpugcc/toolchain/instal

^^ root
1) dont run the desktop as root
2) dont download things into root
3) do it all as a normal user
i.e edit, build run....

if you need to install it somewhere then sudo install .... but never run as root normally
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
PeterO
Posts: 5456
Joined: Sun Jul 22, 2012 4:14 pm

Re: Overcoming a GCC 'sudo' issue

Fri Feb 14, 2020 2:59 pm

Are you sure you wern't running as root when did the untar step ?

I can't see how the files could have got into /root unless you were running as root.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

hippy
Posts: 6766
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Overcoming a GCC 'sudo' issue

Fri Feb 14, 2020 3:12 pm

RaTTuS wrote:
Fri Feb 14, 2020 2:58 pm
if you need to install it somewhere then sudo install .... but never run as root normally
PeterO wrote:
Fri Feb 14, 2020 2:59 pm
Are you sure you wern't running as root when did the untar step ?

I can't see how the files could have got into /root unless you were running as root.
I am not running as root, just as the normal Pi user. Nothing has been installed as root. The installation was exactly as show in the OP. Download, extract, run from a sub-directory under /home/pi

There are no files I put in root, nor did the installation. The problem appears to be that the compiler believes there may be files in /root, fails because it can't access /root because it's not run as root.

User avatar
PeterO
Posts: 5456
Joined: Sun Jul 22, 2012 4:14 pm

Re: Overcoming a GCC 'sudo' issue

Fri Feb 14, 2020 3:28 pm

I downloaded it and I now see what you mean.

Code: Select all

~/armhf-zpu-elf-gcc-3.4.2/bin $ strings zpu-elf-gcc | grep root
../gcc/configure --target=zpu-elf --prefix=/root/Downloads/zpugcc/toolchain/gccbuild/../install --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --with-newlib --disable-shared --enable-newlib -v --enable-checking=misc,tree,rtl,rtlflag,gc,gcac,fold --disable-multilib --disable-threads --enable-sjlj-exceptions --enable-libstdcxx-allocator=malloc
/root/Downloads/zpugcc/toolchain/gccbuild/../install/lib/gcc/
/root/Downloads/zpugcc/toolchain/gccbuild/../install/bin/
/root/Downloads/zpugcc/toolchain/gccbuild/../install/libexec/gcc/
sysroot_suffix_spec
sysroot_hdrs_suffix_spec
  -print-multi-directory   Display the root directory for versions of libgcc
-isysroot
/root/Downloads/zpugcc/toolchain/gccbuild/../install/share/locale
/root/Downloads/zpugcc/toolchain/gccbuild/../install
target_system_root
target_system_root_changed
target_sysroot_suffix
target_sysroot_hdrs_suffix
sysroot_suffix_spec
sysroot_hdrs_suffix_spec
add_sysrooted_prefix
Looks like it's been built incorrectly . I doubt those paths into /root should be in there !
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

hippy
Posts: 6766
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Overcoming a GCC 'sudo' issue

Fri Feb 14, 2020 7:18 pm

PeterO wrote:
Fri Feb 14, 2020 3:28 pm
Looks like it's been built incorrectly . I doubt those paths into /root should be in there !
Thanks; that pointed to the path to salvation. Replaced every occurrence of "/root/Downloads/" with "/home/pi/shazam/" in every file in the tree and now it works without 'sudo'.

Will maybe look for somewhere better to point them at, and make sure I've found any hiding in unicode or other endian forms waiting to bite me.

And I think I've got the (same) explanation as to why the PiDuino framework doesn't work on a Pi without launching the desktop Arduino IDE with 'sudo'.

I had tried building from source but that was another "Why does nothing ever seem to work on Linux?" venture into the circles of hell. The official source and two other forks all failed with varying errors.

Code: Select all

[email protected]:~/zpugcc $ ./armhf-zpu-elf-gcc-3.4.2/bin/zpu-elf-gcc -S fibo.c
[email protected]:~/zpugcc $ ls -l fibo.*
-rw-r--r-- 1 pi pi  170 Feb 14 14:29 fibo.c
-rw-r--r-- 1 pi pi 1303 Feb 14 19:17 fibo.s

Return to “Troubleshooting”