Skip to contentSkip to conversation

Fix C compatibility issue in mini-os

PATCH In review Florian Weimer 3 participants 5 messages Dec 15, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix C compatibility issue in mini-os

The cc-option check always fails (that, it picks the second option unconditionally) if the compiler does not support implicit conversion from integers to pointers. Just drop the initialization because it seems unnecessary in this context.

Related to:

<https://fedoraproject.org/wiki/Changes/PortingToModernC>
<https://fedoraproject.org/wiki/Toolchain/PortingToModernC>

Config.mk +1 -1
index f2d1f0a..b7c9887 100644
@@ -21,7 +21,7 @@ endef
 # of which would indicate an "unrecognized command-line option" warning/error.
 #
 # Usage: cflags-y += $(call cc-option,$(CC),-march=winchip-c6,-march=i586)
-cc-option = $(shell if test -z "`echo 'void*p=1;' | \
+cc-option = $(shell if test -z "`echo 'void*p;' | \
               $(1) $(2) -c -o /dev/null -x c - 2>&1 | grep -- $(2) -`"; \
               then echo "$(2)"; else echo "$(3)"; fi ;)
 
#1 lore raw
Quoted 4 lines · Florian Weimer

The cc-option check always fails (that, it picks the second option unconditionally) if the compiler does not support implicit conversion from integers to pointers. Just drop the initialization because it seems unnecessary in this context.

Did you pay attention to ...

Config.mk endef · line 21

Quoted 4 lines
Config.mk +0 -0
@@ -21,7 +21,7 @@ endef
 # of which would indicate an "unrecognized command-line option" warning/error.

... the comment the tail of which is visible here?

Jan

Quoted 9 lines
Config.mk +1 -1
 #
 # Usage: cflags-y += $(call cc-option,$(CC),-march=winchip-c6,-march=i586)
-cc-option = $(shell if test -z "`echo 'void*p=1;' | \
+cc-option = $(shell if test -z "`echo 'void*p;' | \
               $(1) $(2) -c -o /dev/null -x c - 2>&1 | grep -- $(2) -`"; \
               then echo "$(2)"; else echo "$(3)"; fi ;)
 
#2 lore raw

* Jan Beulich:

Quoted 6 lines · Florian Weimer
Quoted 4 lines

The cc-option check always fails (that, it picks the second option unconditionally) if the compiler does not support implicit conversion from integers to pointers. Just drop the initialization because it seems unnecessary in this context.

Quoted 8 lines

Did you pay attention to ...

Config.mk endef · line 21

Quoted 4 lines
Config.mk +0 -0
@@ -21,7 +21,7 @@ endef
 # of which would indicate an "unrecognized command-line option" warning/error.

... the comment the tail of which is visible here?

I didn't investigate how the mechanics of the selection are accomplished. I was so happy that I finally found the source of the int-conversion error and got a bit carried away.

Looking at the shell script fragment:

Quoted 5 lines

Config.mk endef · line 26

Quoted 5 lines
Config.mk +1 -1
 # Usage: cflags-y += $(call cc-option,$(CC),-march=winchip-c6,-march=i586)
-cc-option = $(shell if test -z "`echo 'void*p=1;' | \
+cc-option = $(shell if test -z "`echo 'void*p;' | \
               $(1) $(2) -c -o /dev/null -x c - 2>&1 | grep -- $(2) -`"; \
               then echo "$(2)"; else echo "$(3)"; fi ;)

I can see that the exit status of the compiler does not matter, so the patch will not make a difference.

I'll record this as a false positive.

Thanks,
Florian

#3 lore raw
Quoted 23 lines · Florian Weimer

* Jan Beulich:

Quoted 6 lines · Florian Weimer
Quoted 4 lines

The cc-option check always fails (that, it picks the second option unconditionally) if the compiler does not support implicit conversion from integers to pointers. Just drop the initialization because it seems unnecessary in this context.

Quoted 8 lines

Did you pay attention to ...

Config.mk endef · line 21

Quoted 4 lines
Config.mk +0 -0
@@ -21,7 +21,7 @@ endef
 # of which would indicate an "unrecognized command-line option" warning/error.

... the comment the tail of which is visible here?

I didn't investigate how the mechanics of the selection are accomplished. I was so happy that I finally found the source of the int-conversion error and got a bit carried away.

Looking at the shell script fragment:

Quoted 8 lines
Quoted 5 lines

Config.mk endef · line 26

Quoted 5 lines
Config.mk +1 -1
 # Usage: cflags-y += $(call cc-option,$(CC),-march=winchip-c6,-march=i586)
-cc-option = $(shell if test -z "`echo 'void*p=1;' | \
+cc-option = $(shell if test -z "`echo 'void*p;' | \
               $(1) $(2) -c -o /dev/null -x c - 2>&1 | grep -- $(2) -`"; \
               then echo "$(2)"; else echo "$(3)"; fi ;)

I can see that the exit status of the compiler does not matter, so the patch will not make a difference.

An option may be to use Xen's (newer) variant

cc-option = $(shell if $(1) $(2:-Wno-%=-W%) -Werror -c -o /dev/null -x c /dev/null >/dev/null 2>&1; \
              then echo "$(2)"; else echo "$(3)"; fi ;)

here as well (omitted all commentary). Cc-ing maintainers for possible input.

Jan

#4 lore raw
Quoted 33 lines · Jan Beulich
Quoted 23 lines · Florian Weimer

* Jan Beulich:

Quoted 6 lines · Florian Weimer
Quoted 4 lines

The cc-option check always fails (that, it picks the second option unconditionally) if the compiler does not support implicit conversion from integers to pointers. Just drop the initialization because it seems unnecessary in this context.

Quoted 8 lines

Did you pay attention to ...

Config.mk endef · line 21

Quoted 4 lines
Config.mk +0 -0
@@ -21,7 +21,7 @@ endef
  # of which would indicate an "unrecognized command-line option" warning/error.

... the comment the tail of which is visible here?

I didn't investigate how the mechanics of the selection are accomplished. I was so happy that I finally found the source of the int-conversion error and got a bit carried away.

Looking at the shell script fragment:

Quoted 8 lines
Quoted 5 lines

Config.mk endef · line 26

Quoted 5 lines
Config.mk +1 -1
  # Usage: cflags-y += $(call cc-option,$(CC),-march=winchip-c6,-march=i586)
-cc-option = $(shell if test -z "`echo 'void*p=1;' | \
+cc-option = $(shell if test -z "`echo 'void*p;' | \
                $(1) $(2) -c -o /dev/null -x c - 2>&1 | grep -- $(2) -`"; \
                then echo "$(2)"; else echo "$(3)"; fi ;)

I can see that the exit status of the compiler does not matter, so the patch will not make a difference.

Quoted 7 lines

An option may be to use Xen's (newer) variant

cc-option = $(shell if $(1) $(2:-Wno-%=-W%) -Werror -c -o /dev/null -x c /dev/null >/dev/null 2>&1; \
               then echo "$(2)"; else echo "$(3)"; fi ;)

here as well (omitted all commentary). Cc-ing maintainers for possible input.

There is no urgent need for that, as in Mini-OS I'm not aware of any use case to test for a "-W..." option, but the approach is really cleaner IMO.

Juergen