Bug#317233: gcc-4.0 regression, possibly powerpc-specific, causes segfault in compiled binary
Matthias Klose <doko@cs.tu-berlin.de> writes:
>> If it would be useful, I can reduce it to a smaller test case, but the
>> code worked just fine with 3.3.
>
> yes, it would be useful.
Attached, though it's more a test of success than failure.
This differs from the fix I mentioned in the previous mail, in that I
stripped everything out except for the option parsing, *but* I didn't
make the options const. However, it works without me applying the
const fix.
Build with
gcc -o schroot schroot.c `pkg-config --cflags --libs gobject-2.0`
Regards,
Roger
--
Roger Leigh
Printing on GNU/Linux? http://gimp-print.sourceforge.net/
Debian GNU/Linux http://www.debian.org/
GPG Public Key: 0x25BFB848. Please sign and encrypt your mail.
/* schroot - securely enter a chroot
*
* Copyright © 2005 Roger Leigh <rleigh@debian.org>
*
* schroot is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* schroot is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*********************************************************************/
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
#include <syslog.h>
#include <libintl.h>
#include <glib.h>
#include <glib/gi18n.h>
/* Stored command-line options. */
static struct {
char **chroots;
char **command;
char *user;
gboolean preserve;
gboolean quiet;
gboolean list;
gboolean info;
gboolean all;
gboolean version;
} opt =
{
.chroots = NULL,
.command = NULL,
.user = NULL,
.preserve = FALSE,
.quiet = FALSE,
.list = FALSE,
.info = FALSE,
.all = FALSE,
.version = FALSE
};
/* Command-line options. */
static GOptionEntry entries[] =
{
{ "all", 'a', 0, G_OPTION_ARG_NONE, &opt.all, N_("Run command in all chroots"), NULL },
{ "chroot", 'c', 0, G_OPTION_ARG_STRING_ARRAY, &opt.chroots, N_("Use specified chroot"), "chroot" },
{ "user", 'u', 0, G_OPTION_ARG_STRING, &opt.user, N_("Username (default current user)"), "user" },
{ "list", 'l', 0, G_OPTION_ARG_NONE, &opt.list, N_("List available chroots"), NULL },
{ "info", 'i', 0, G_OPTION_ARG_NONE, &opt.info, N_("Show information about chroot"), NULL },
{ "preserve-environment", 'p', 0, G_OPTION_ARG_NONE, &opt.preserve, N_("Preserve user environment"), NULL },
{ "quiet", 'q', 0, G_OPTION_ARG_NONE, &opt.quiet, N_("Show less output"), NULL },
{ "version", 'V', 0, G_OPTION_ARG_NONE, &opt.version, N_("Print version information"), NULL },
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt.command, NULL, NULL }
};
/**
* parse_options:
* @argc: the number of arguments
* @argv: argument vector
*
* Parse command-line options. The options are places in the opt
* structure.
*/
static void
parse_options(int argc,
char *argv[])
{
GError *error = NULL;
GOptionContext *context = g_option_context_new (_("- run command or shell in a chroot"));
g_option_context_add_main_entries (context, entries, "schroot");
g_option_context_parse (context, &argc, &argv, &error);
}
/**
* print_version:
* @file: the file to print to
*
* Print version information.
*/
void
print_version (FILE *file)
{
g_fprintf(file, _("schroot (Debian sbuild) %s\n"), "gcc-debug");
g_fprintf(file, _("Written by Roger Leigh\n\n"));
g_fprintf(file, _("Copyright (C) 2004-2005 Roger Leigh\n"));
g_fprintf(file, _("This is free software; see the source for copying conditions. There is NO\n"
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"));
}
/**
* debug_logfunc:
* @log_domain: the log domain
* @log_level: the logging level
* @message: the message to log
* @user_data: extra detail
*
* Log a debugging message. This is a "NULL" message handler that
* does nothing, discarding all messages.
*/
void debug_logfunc (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data)
{
/* Discard all messages. */
}
/**
* main:
* @argc: the number of arguments
* @argv: argument vector
*
* Main routine.
*
* Returns 0 on success, 1 on failure.
*/
int
main (int argc,
char *argv[])
{
g_type_init();
setlocale (LC_ALL, "");
bindtextdomain ("schroot", "/usr/share/locale");
textdomain ("schroot");
#ifndef SBUILD_DEBUG
/* Discard g_debug output for this logging domain. */
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, debug_logfunc, NULL);
#endif
openlog("schroot", LOG_PID|LOG_NDELAY, LOG_AUTHPRIV);
/* Parse command-line options into opt structure. */
parse_options(argc, argv);
if (opt.version == TRUE)
{
print_version(stdout);
exit(EXIT_SUCCESS);
}
exit (EXIT_SUCCESS);
}
Reply to: