Opened 3 years ago

Closed 3 years ago

#65128 closed defect (fixed)

xar @1.8.0.487.100.1: error: variable-sized object may not be initialized

Reported by: barracuda156 Owned by: Schamschula (Marius Schamschula)
Priority: Normal Milestone:
Component: ports Version: 2.7.2
Keywords: powerpc, tiger, leopard, snowleopard Cc:
Port: xar

Description (last modified by barracuda156)

:info:build Executing:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_archivers_xar/xar/work/xar-487.100.1/xar" && /usr/bin/make -j4 -w all 
:debug:build system:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_archivers_xar/xar/work/xar-487.100.1/xar" && /usr/bin/make -j4 -w all 
:info:build make: Entering directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_archivers_xar/xar/work/xar-487.100.1/xar'
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/archive.c -o lib/archive.o
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/bzxar.c -o lib/bzxar.o
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/b64.c -o lib/b64.o
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/arcmod.c -o lib/arcmod.o
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/darwinattr.c -o lib/darwinattr.o
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/data.c -o lib/data.o
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/ea.c -o lib/ea.o
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/err.c -o lib/err.o
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/ext2.c -o lib/ext2.o
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/fbsdattr.c -o lib/fbsdattr.o
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/filetree.c -o lib/filetree.o
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/io.c -o lib/io.o
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/lzmaxar.c -o lib/lzmaxar.o
:info:build /opt/local/bin/gcc-mp-11 -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc  -fPIC -DPIC -dynamic -Iinclude -Iinclude -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -I/opt/local/include/libxml2 -c lib/linuxattr.c -o lib/linuxattr.o
:info:build lib/filetree.c: In function 'xar_file_equals_file':
:info:build lib/filetree.c:744:9: error: variable-sized object may not be initialized
:info:build   744 |         char * keys_to_ignore[keys_to_ignore_count] = { "id" }; // ID is allowed ot mismatch
:info:build       |         ^~~~
:info:build make: *** [lib/filetree.o] Error 1
:info:build make: *** Waiting for unfinished jobs....
:info:build make: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_archivers_xar/xar/work/xar-487.100.1/xar'
:info:build Command failed:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_archivers_xar/xar/work/xar-487.100.1/xar" && /usr/bin/make -j4 -w all 
:info:build Exit code: 2
:error:build Failed to build xar: command execution failed
:debug:build Error code: CHILDSTATUS 70012 2
:debug:build Backtrace: command execution failed
:debug:build     while executing
:debug:build "system {*}$notty {*}$callback {*}$nice $fullcmdstring"
:debug:build     invoked from within
:debug:build "command_exec -callback portprogress::target_progress_callback build"
:debug:build     (procedure "portbuild::build_main" line 8)
:debug:build     invoked from within
:debug:build "$procedure $targetname"

The identical failure confirmed on 10.4.11 and 10.6, will check 10.5.8 soon. (On Tiger it fails using gcc7.)

Attachments (2)

main-10.4.11.log (55.0 KB) - added by barracuda156 3 years ago.
patch-filetree.diff (645 bytes) - added by barracuda156 3 years ago.
Like this?

Download all attachments as: .zip

Change History (28)

comment:1 Changed 3 years ago by barracuda156

Description: modified (diff)
Summary: xar fails to upgrade to @@1.8.0.487.100.1 on PowerPCxar fails to upgrade to @1.8.0.487.100.1 on PowerPC

Changed 3 years ago by barracuda156

Attachment: main-10.4.11.log added

comment:2 Changed 3 years ago by barracuda156

As expected, it also fails on Leopard with the same error:

lib/filetree.c: In function 'xar_file_equals_file':
lib/filetree.c:744:9: error: variable-sized object may not be initialized
  744 |         char * keys_to_ignore[keys_to_ignore_count] = { "id" }; // ID is allowed ot mismatch
      |         ^~~~
make: *** [lib/filetree.o] Error 1
make: *** Waiting for unfinished jobs....
make: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_archivers_xar/xar/work/xar-487.100.1/xar'
Command failed:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_archivers_xar/xar/work/xar-487.100.1/xar" && /usr/bin/make -j4 -w all 
Exit code: 2

comment:3 Changed 3 years ago by barracuda156

Keywords: leopard added

comment:4 Changed 3 years ago by ryandesign (Ryan Carsten Schmidt)

Owner: set to Schamschula
Status: newassigned
Summary: xar fails to upgrade to @1.8.0.487.100.1 on PowerPCxar @1.8.0.487.100.1: error: variable-sized object may not be initialized

We saw the same error on systems as new as macOS 10.15:

https://build.macports.org/builders/ports-10.15_x86_64-builder/builds/98836/steps/install-port/logs/stdio

but then Marius conmitted [874b9b8ca44c29b72455d722a5dd54e312c0e820/macports-ports] which fixed the build on all buildbot systems (10.6 and up). Does that help your systems? If not maybe a different -std needs to be specified. I see that Marius's fix included removing -std=c99 and telling MacPorts to pick a C11 compiler, but there is no corresponding -std=c11 flag in your log.

comment:5 in reply to:  4 ; Changed 3 years ago by ryandesign (Ryan Carsten Schmidt)

Replying to ryandesign:

If not maybe a different -std needs to be specified.

Like you could try adding

configure.cflags-append -std=c11

to the Portfile.

comment:6 Changed 3 years ago by Schamschula (Marius Schamschula)

I certainly can add configure.cflags-append -std=c11, but it seemed redundant at the time, particularly since all buildbots succeeded.

comment:7 in reply to:  6 Changed 3 years ago by barracuda156

Replying to Schamschula:

I certainly can add configure.cflags-append -std=c11, but it seemed redundant at the time, particularly since all buildbots succeeded.

Well, unless someone confirms that xar builds as-is on PPC, a fix is definitely not redundant, since at least on my end it fails on all three PPC systems. (Buildbots are irrelevant here, there are none for PPC.)

comment:8 in reply to:  5 Changed 3 years ago by barracuda156

Replying to ryandesign:

Like you could try adding

configure.cflags-append -std=c11

to the Portfile.

Let me try that, thanks for suggestion.

UPD. Makes no difference, unfortunately.

Last edited 3 years ago by barracuda156 (previous) (diff)

comment:9 Changed 3 years ago by Schamschula (Marius Schamschula)

Are you sure that a C11 compiler is actually used?

comment:10 Changed 3 years ago by kencu (Ken)

gcc11 already defaults to a quite new C standard.

This whole issue of variable- length arrays (VLAs), how they are set up and initialized, and how different compilers and different versions of compilers handle it is somewhat interesting reading…there’s a lot out there about this topic.

this code should probably be rewritten to initialize manually rather than automatically, I think, to be more compatible.

Last edited 3 years ago by kencu (Ken) (previous) (diff)

comment:11 Changed 3 years ago by kencu (Ken)

I can't get any version of gcc to compile this code with any c standard:

typedef unsigned int uint;

int main(void) {
  const uint keys_to_ignore_count = 1;
  char * keys_to_ignore[keys_to_ignore_count] = { "id" }; // ID is allowed ot mismatch
  return (0);
}

comment:12 Changed 3 years ago by kencu (Ken)

this works, no surprise

typedef unsigned int uint;

int main(void) {
//  const uint keys_to_ignore_count = 1;
#define keys_to_ignore_count 1
  char * keys_to_ignore[keys_to_ignore_count] = { "id" }; // ID is allowed ot mismatch
  return (0);
}

comment:13 Changed 3 years ago by kencu (Ken)

this works with gcc11 too:

#include <stdio.h>

typedef unsigned int uint;

int main(void) {
  const uint keys_to_ignore_count = 1;

  char * keys_to_ignore[keys_to_ignore_count];
  keys_to_ignore[0] = "id"; // ID is allowed ot mismatch

  printf("Keys to ignore: %s\n\n", keys_to_ignore[0]);

  return (0);
}

comment:14 Changed 3 years ago by Schamschula (Marius Schamschula)

As I researched the original issue, I saw similar posts regarding variable sized arrays.

However, as the code is from Apple, and it cleanly compiled under Big Sur and Monterey, I guessed that new compilers accepted this code. Hence, I tried setting compiler.c_standard 2011, which worked for all Intel and Apple SoC machines.

comment:15 Changed 3 years ago by Schamschula (Marius Schamschula)

Comment 12 is most likely to work on the PPC platform. Let me know if it does, so I can add the patch.

comment:16 in reply to:  11 Changed 3 years ago by barracuda156

Replying to kencu:

I can't get any version of gcc to compile this code with any c standard:

typedef unsigned int uint;

int main(void) {
  const uint keys_to_ignore_count = 1;
  char * keys_to_ignore[keys_to_ignore_count] = { "id" }; // ID is allowed ot mismatch
  return (0);
}

So this is not even a PPC issue, but gcc issue in general?

comment:17 in reply to:  15 Changed 3 years ago by barracuda156

Replying to Schamschula:

Comment 12 is most likely to work on the PPC platform. Let me know if it does, so I can add the patch.

Let me make a patch and try it.

UPD. Yes, xar builds with that.

Last edited 3 years ago by barracuda156 (previous) (diff)

Changed 3 years ago by barracuda156

Attachment: patch-filetree.diff added

Like this?

comment:18 Changed 3 years ago by kencu (Ken)

I think it is a gcc / clang difference.

Quite possibly clang should not accept that code, but does. I saw something about it being accepted after a certain clang version (3.something) so maybe that is why forcing a newer clang worked.

Anyways, some simple enough options. I guess the patch would hinge on whether gcc was the build compiler -- or could just be always applied, and then probably no need for forcing a c11 compiler at all I would think.

Up to you.

comment:19 in reply to:  14 ; Changed 3 years ago by ryandesign (Ryan Carsten Schmidt)

Replying to Schamschula:

Hence, I tried setting compiler.c_standard 2011, which worked for all Intel and Apple SoC machines.

What worked was removing -std=c99, returning clang to its default -std=gnu99 mode; requiring a 2011 compiler does not seem to be relevant since c11 mode is not being enabled via -std=c11.

comment:20 in reply to:  19 ; Changed 3 years ago by kencu (Ken)

Replying to ryandesign:

Replying to Schamschula:

Hence, I tried setting compiler.c_standard 2011, which worked for all Intel and Apple SoC machines.

What worked was removing -std=c99, returning clang to its default -std=gnu99 mode; requiring a 2011 compiler does not seem to be relevant since c11 mode is not being enabled via -std=c11.

using std=gnu99 doesn't make gcc11 happy:

$ cat arraytest1.c
typedef unsigned int uint;

int main(void) {
  const uint keys_to_ignore_count = 1;
  char * keys_to_ignore[keys_to_ignore_count] = { "id" }; // ID is allowed ot mismatch
  return (0);
}

$ /opt/local/bin/gcc-mp-11 -std=gnu99 -c arraytest1.c
arraytest1.c: In function 'main':
arraytest1.c:5:3: error: variable-sized object may not be initialized
    5 |   char * keys_to_ignore[keys_to_ignore_count] = { "id" }; // ID is allowed ot mismatch
      |   ^~~~

I haven't tried any other compilers.

comment:21 in reply to:  20 Changed 3 years ago by ryandesign (Ryan Carsten Schmidt)

Replying to kencu:

using std=gnu99 doesn't make gcc11 happy

I know it doesn't. But that was the part of the change that made clang happy, not the requirement of C11 compiler.

comment:22 Changed 3 years ago by Schamschula (Marius Schamschula)

It seems to be so. I'll delete compiler.c_standard 2011.

However, I'm not able to test older OS versions, particularly PPC machines.

comment:23 Changed 3 years ago by kencu (Ken)

It turns out this code is very very touchy to the exact compiler and compiler version used, and for clang, in some cases the standard set.

You can explore them all here:

https://godbolt.org/z/5Kv8dehKf

This has nothing to do with PPC machines, other than the PPC machines compile with gcc.

comment:24 Changed 3 years ago by Schamschula (Marius Schamschula)

From the compiler explorer, it looks like clang < 12.0.0 also fails.

Last edited 3 years ago by Schamschula (Marius Schamschula) (previous) (diff)

comment:25 Changed 3 years ago by kencu (Ken)

and clang >= 12 succeeds, even with -std=c99 !

I suspect we'll see this rewritten next version of xar :>

Last edited 3 years ago by kencu (Ken) (previous) (diff)

comment:26 Changed 3 years ago by Schamschula (Marius Schamschula)

Resolution: fixed
Status: assignedclosed

In bd455f9996fc57626fb35b3d40e85db053f90520/macports-ports (master):

xar: fix gcc build issue (lib/filetree.c)

Closes: #65128

Note: See TracTickets for help on using tickets.