Dr-Noob / cpufetch

Simple yet fancy CPU architecture fetching tool
GNU General Public License v2.0
1.83k stars 100 forks source link

Building with clang fails on ppc64le #151

Closed pkubaj closed 1 year ago

pkubaj commented 1 year ago

I'm in the middle of porting cpufetch to FreeBSD/powerpc*. However, building on FreeBSD fails in peculiar ways. As you may know, FreeBSD uses clang by default and I checked whether it fails the same way on Linux. Turns out it is:

/usr/lib/llvm/14/bin/clang -Wall -Wextra -pedantic -DARCH_PPC -std=gnu99 -fstack-protector-all -O2 -Wfloat-equal -Wshadow -Wpointer-arith src/common/main.c src/common/cpu.c src/common/udev.c src/common/printer.c src/common/args.c src/common/global.c src/ppc/ppc.c src/ppc/uarch.c src/ppc/udev.c -o cpufetch
In file included from src/common/main.c:5:
In file included from src/common/args.h:40:
src/common/printer.h:29:28: warning: declaration of 'struct cpuInfo' will not be visible outside of this function [-Wvisibility]
bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs, bool fcpuname);
                           ^
src/common/main.c:129:25: warning: implicit declaration of function 'get_cpu_info' is invalid in C99 [-Wimplicit-function-declaration]
  struct cpuInfo* cpu = get_cpu_info();
                        ^
src/common/main.c:129:19: warning: incompatible integer to pointer conversion initializing 'struct cpuInfo *' with an expression of type 'int' [-Wint-conversion]
  struct cpuInfo* cpu = get_cpu_info();
                  ^     ~~~~~~~~~~~~~~
src/common/main.c:135:5: warning: implicit declaration of function 'print_debug' is invalid in C99 [-Wimplicit-function-declaration]
    print_debug(cpu);
    ^
src/common/main.c:151:21: warning: incompatible pointer types passing 'struct cpuInfo *' to parameter of type 'struct cpuInfo *' [-Wincompatible-pointer-types]
  if(print_cpufetch(cpu, get_style(), get_colors(), show_full_cpu_name()))
                    ^~~
src/common/printer.h:29:37: note: passing argument to parameter 'cpu' here
bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs, bool fcpuname);
                                    ^
5 warnings generated.
In file included from src/common/printer.c:8:
src/common/printer.h:29:28: warning: declaration of 'struct cpuInfo' will not be visible outside of this function [-Wvisibility]
bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs, bool fcpuname);
                           ^
src/common/printer.c:611:19: warning: implicit declaration of function 'get_str_topology' is invalid in C99 [-Wimplicit-function-declaration]
  char* n_cores = get_str_topology(cpu->topo, false);
                  ^
src/common/printer.c:611:9: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]
  char* n_cores = get_str_topology(cpu->topo, false);
        ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/common/printer.c:612:9: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]
  char* n_cores_dual = get_str_topology(cpu->topo, true);
        ^              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/common/printer.c:613:19: warning: implicit declaration of function 'get_str_altivec' is invalid in C99 [-Wimplicit-function-declaration]
  char* altivec = get_str_altivec(cpu);
                  ^
src/common/printer.c:613:9: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]
  char* altivec = get_str_altivec(cpu);
        ^         ~~~~~~~~~~~~~~~~~~~~
src/common/printer.c:904:6: error: conflicting types for 'print_cpufetch'
bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs, bool show_full_cpu_name) {
     ^
src/common/printer.h:29:6: note: previous declaration is here
bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs, bool fcpuname);
     ^
6 warnings and 1 error generated.
In file included from src/common/args.c:5:
In file included from src/common/args.h:40:
src/common/printer.h:29:28: warning: declaration of 'struct cpuInfo' will not be visible outside of this function [-Wvisibility]
bool print_cpufetch(struct cpuInfo* cpu, STYLE s, struct color** cs, bool fcpuname);
                           ^
1 warning generated.
In file included from src/ppc/ppc.c:9:
src/ppc/uarch.h:10:1: error: unknown type name 'bool'
bool has_altivec(struct uarch* arch);
^
src/ppc/uarch.h:11:1: error: unknown type name 'bool'
bool is_power9(struct uarch* arch);
^
src/ppc/uarch.h:12:28: warning: declaration of 'struct cpuInfo' will not be visible outside of this function [-Wvisibility]
char* get_str_uarch(struct cpuInfo* cpu);
                           ^
src/ppc/uarch.h:13:30: warning: declaration of 'struct cpuInfo' will not be visible outside of this function [-Wvisibility]
char* get_str_process(struct cpuInfo* cpu);
                             ^
src/ppc/ppc.c:117:5: warning: extension used [-Wlanguage-extension-token]
    asm ("mfpvr %0"
    ^
3 warnings and 2 errors generated.
In file included from src/ppc/uarch.c:9:
src/ppc/uarch.h:12:28: warning: declaration of 'struct cpuInfo' will not be visible outside of this function [-Wvisibility]
char* get_str_uarch(struct cpuInfo* cpu);
                           ^
src/ppc/uarch.h:13:30: warning: declaration of 'struct cpuInfo' will not be visible outside of this function [-Wvisibility]
char* get_str_process(struct cpuInfo* cpu);
                             ^
src/ppc/uarch.c:258:28: warning: declaration of 'struct cpuInfo' will not be visible outside of this function [-Wvisibility]
char* get_str_uarch(struct cpuInfo* cpu) {
                           ^
src/ppc/uarch.c:258:7: error: conflicting types for 'get_str_uarch'
char* get_str_uarch(struct cpuInfo* cpu) {
      ^
src/ppc/uarch.h:12:7: note: previous declaration is here
char* get_str_uarch(struct cpuInfo* cpu);
      ^
src/ppc/uarch.c:259:13: error: incomplete definition of type 'struct cpuInfo'
  return cpu->arch->uarch_str;
         ~~~^
src/ppc/uarch.c:258:28: note: forward declaration of 'struct cpuInfo'
char* get_str_uarch(struct cpuInfo* cpu) {
                           ^
src/ppc/uarch.c:262:30: warning: declaration of 'struct cpuInfo' will not be visible outside of this function [-Wvisibility]
char* get_str_process(struct cpuInfo* cpu) {
                             ^
src/ppc/uarch.c:262:7: error: conflicting types for 'get_str_process'
char* get_str_process(struct cpuInfo* cpu) {
      ^
src/ppc/uarch.h:13:7: note: previous declaration is here
char* get_str_process(struct cpuInfo* cpu);
      ^
src/ppc/uarch.c:264:24: error: incomplete definition of type 'struct cpuInfo'
  int32_t process = cpu->arch->process;
                    ~~~^
src/ppc/uarch.c:262:30: note: forward declaration of 'struct cpuInfo'
char* get_str_process(struct cpuInfo* cpu) {
                             ^
4 warnings and 4 errors generated.
make: *** [Makefile:83: cpufetch] Error 1

I managed to fix struct cpuInfo-related errors with:

diff --git a/src/common/printer.h b/src/common/printer.h
index 382b0fe..4e28e45 100644
--- a/src/common/printer.h
+++ b/src/common/printer.h
@@ -13,6 +13,8 @@ typedef int STYLE;
   #include "../arm/midr.h"
 #endif

+#include "../common/cpu.h"
+
 //                              +-----------------------------------+-----------------------+
 //                              | Color logo                        | Color text            |
 //                              | Color 1   | Color 2   | Color 3   | Color 1   | Color 2   |
diff --git a/src/ppc/uarch.h b/src/ppc/uarch.h
index f7c45ce..eda4124 100644
--- a/src/ppc/uarch.h
+++ b/src/ppc/uarch.h
@@ -2,6 +2,7 @@
 #define __UARCH__

 #include <stdint.h>
+#include "../common/cpu.h"
 #include "ppc.h"

 struct uarch;

But other errors still remain.

EDIT: the above patch lets cpufetch build successfully and it runs with the same results as with GCC. There are still some warnings remaining.

Dr-Noob commented 1 year ago

I can't reproduce the issue because I don't have a powerpc machine, but I'm a bit suspicious about an issue I found. I pushed a fix in the bugfix branch. Let's see if that helps!

pkubaj commented 1 year ago

Indeed, now it builds, although there's one warning remaining:

src/ppc/ppc.c:117:5: warning: extension used [-Wlanguage-extension-token]
    asm ("mfpvr %0"
    ^
1 warning generated.
Dr-Noob commented 1 year ago

Right, I disabled that warning in the Makefile for ppc compilation. Give it a try again - hopefully, it'll compile seamlessly.

pkubaj commented 1 year ago

Thank you, now it builds without warnings with clang!

Dr-Noob commented 1 year ago

Changes merged into master branch, closing.