From: Sergio Durigan Junior <sergiodj@redhat.com>
To: GDB Patches <gdb-patches@sourceware.org>,
GCC Patches <gcc-patches@gcc.gnu.org>
Cc: Tom Tromey <tom@tromey.com>, Keith Seitz <keiths@redhat.com>,
Phil Muldoon <pmuldoon@redhat.com>,
Alexandre Oliva <aoliva@redhat.com>
Subject: [PATCH 1/2] [GCC] Improve regexp handling on libc[cp]1::compiler_triplet_regexp::find
Date: Wed, 23 Aug 2017 04:18:00 -0000 [thread overview]
Message-ID: <87lgmahq7p.fsf@redhat.com> (raw)
In-Reply-To: <87mv6qhq9u.fsf@redhat.com>
This is the GCC patch.
It adjusts the behaviour of make_regexp in order to not add the "-" at
the end of the triplet regexp. This is now GDB's responsibility.
It also improves the 'find' methods of both
libcc1::compiler_triplet_regexp and libcp1::compiler_triplet_regexp
classes by implementing a detection of a triplet string in the compiler
name. If it finds the triplet there, then the pristine compiler name is
used to match a compiler in the system, without using the initial
triplet regexp provided by GDB. If the compiler name doesn't start with
a triplet, then the old behaviour is maintained and we'll still search
for compilers using the triplet regexp.
With this patch it is possible to include triplets in compiler names
(via the --program-prefix configure option), like Debian does, for
example. I chose not to worry too much about possible suffixes (which
can be specified via --program-suffix) because even with them it is
still possible to find the compiler in the system. It is important to
note that Debian uses suffixes as well.
It is still perfectly possible to find compilers without
prefixes/suffixes, like "gcc" (this is how Fedora names its GCC, by the
way).
OK to apply?
--
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF 31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
libcc1/ChangeLog:
2017-08-23 Sergio Durigan Junior <sergiodj@redhat.com>
* libcc1.cc (make_regexp): Don't add dash after triplet regexp.
Handle case when COMPILER is empty.
(libcc1::compiler_triplet_regexp::find): Detect when
C_COMPILER_NAME already contains a triplet.
* libcp1.cc (make_regexp): Don't add dash after triplet regexp.
Handle case when COMPILER is empty.
(libcp1::compiler_triplet_regexp::find): Detect when
CP_COMPILER_NAME already contains a triplet.
diff --git a/libcc1/libcc1.cc b/libcc1/libcc1.cc
index 0ef6c112dae..41a6e3cca77 100644
--- a/libcc1/libcc1.cc
+++ b/libcc1/libcc1.cc
@@ -336,31 +336,34 @@ make_regexp (const char *triplet_regexp, const char *compiler)
{
std::stringstream buf;
- buf << "^" << triplet_regexp << "-";
+ buf << "^" << triplet_regexp;
- // Quote the compiler name in case it has something funny in it.
- for (const char *p = compiler; *p; ++p)
+ if (compiler[0] != '\0')
{
- switch (*p)
+ // Quote the compiler name in case it has something funny in it.
+ for (const char *p = compiler; *p; ++p)
{
- case '.':
- case '^':
- case '$':
- case '*':
- case '+':
- case '?':
- case '(':
- case ')':
- case '[':
- case '{':
- case '\\':
- case '|':
- buf << '\\';
- break;
+ switch (*p)
+ {
+ case '.':
+ case '^':
+ case '$':
+ case '*':
+ case '+':
+ case '?':
+ case '(':
+ case ')':
+ case '[':
+ case '{':
+ case '\\':
+ case '|':
+ buf << '\\';
+ break;
+ }
+ buf << *p;
}
- buf << *p;
+ buf << "$";
}
- buf << "$";
return buf.str ();
}
@@ -382,12 +385,30 @@ libcc1::compiler::find (std::string &compiler ATTRIBUTE_UNUSED) const
char *
libcc1::compiler_triplet_regexp::find (std::string &compiler) const
{
- std::string rx = make_regexp (triplet_regexp_.c_str (), C_COMPILER_NAME);
+ regex_t triplet;
+ bool c_compiler_has_triplet = false;
+
+ // Some distros, like Debian, choose to use a prefix and a suffix
+ // in their C_COMPILER_NAME, so we try to check if that's the case
+ // here and adjust the regexp's accordingly.
+ std::string triplet_rx = make_regexp (triplet_regexp_.c_str (), "");
+ int code = regcomp (&triplet, triplet_rx.c_str (), REG_EXTENDED | REG_NOSUB);
+
+ if (code == 0)
+ {
+ if (regexec (&triplet, C_COMPILER_NAME, 0, NULL, 0) == 0)
+ c_compiler_has_triplet = true;
+
+ regfree (&triplet);
+ }
+
+ std::string rx = make_regexp (c_compiler_has_triplet
+ ? "" : triplet_regexp_.c_str (),
+ C_COMPILER_NAME);
if (self_->verbose)
fprintf (stderr, _("searching for compiler matching regex %s\n"),
rx.c_str());
- regex_t triplet;
- int code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
+ code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
if (code != 0)
{
size_t len = regerror (code, &triplet, NULL, 0);
diff --git a/libcc1/libcp1.cc b/libcc1/libcp1.cc
index bbd8488af93..5bac6e4e37c 100644
--- a/libcc1/libcp1.cc
+++ b/libcc1/libcp1.cc
@@ -360,31 +360,34 @@ make_regexp (const char *triplet_regexp, const char *compiler)
{
std::stringstream buf;
- buf << "^" << triplet_regexp << "-";
+ buf << "^" << triplet_regexp;
- // Quote the compiler name in case it has something funny in it.
- for (const char *p = compiler; *p; ++p)
+ if (compiler[0] != '\0')
{
- switch (*p)
+ // Quote the compiler name in case it has something funny in it.
+ for (const char *p = compiler; *p; ++p)
{
- case '.':
- case '^':
- case '$':
- case '*':
- case '+':
- case '?':
- case '(':
- case ')':
- case '[':
- case '{':
- case '\\':
- case '|':
- buf << '\\';
- break;
+ switch (*p)
+ {
+ case '.':
+ case '^':
+ case '$':
+ case '*':
+ case '+':
+ case '?':
+ case '(':
+ case ')':
+ case '[':
+ case '{':
+ case '\\':
+ case '|':
+ buf << '\\';
+ break;
+ }
+ buf << *p;
}
- buf << *p;
+ buf << "$";
}
- buf << "$";
return buf.str ();
}
@@ -406,12 +409,30 @@ libcp1::compiler::find (std::string &compiler ATTRIBUTE_UNUSED) const
char *
libcp1::compiler_triplet_regexp::find (std::string &compiler) const
{
- std::string rx = make_regexp (triplet_regexp_.c_str (), CP_COMPILER_NAME);
+ regex_t triplet;
+ bool cp_compiler_name_has_triplet = false;
+
+ // Some distros, like Debian, choose to use a prefix and a suffix
+ // in their CP_COMPILER_NAME, so we try to check if that's the case
+ // here and adjust the regexp's accordingly.
+ std::string triplet_rx = make_regexp (triplet_regexp_.c_str (), "");
+ int code = regcomp (&triplet, triplet_rx.c_str (), REG_EXTENDED | REG_NOSUB);
+
+ if (code == 0)
+ {
+ if (regexec (&triplet, CP_COMPILER_NAME, 0, NULL, 0) == 0)
+ cp_compiler_name_has_triplet = true;
+
+ regfree (&triplet);
+ }
+
+ std::string rx = make_regexp (cp_compiler_name_has_triplet
+ ? "" : triplet_regexp_.c_str (),
+ CP_COMPILER_NAME);
if (self_->verbose)
fprintf (stderr, _("searching for compiler matching regex %s\n"),
rx.c_str());
- regex_t triplet;
- int code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
+ code = regcomp (&triplet, rx.c_str (), REG_EXTENDED | REG_NOSUB);
if (code != 0)
{
size_t len = regerror (code, &triplet, NULL, 0);
next prev parent reply other threads:[~2017-08-23 4:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-23 4:17 [libcc1] Improve detection of triplet on compiler names Sergio Durigan Junior
2017-08-23 4:18 ` Sergio Durigan Junior [this message]
2017-08-23 4:18 ` [PATCH 2/2] [GDB] Add trailing dash on triplet regexp Sergio Durigan Junior
2017-08-23 9:20 ` [libcc1] Improve detection of triplet on compiler names Pedro Alves
[not found] ` <87a82qh1pn.fsf@redhat.com>
2017-08-23 13:15 ` Pedro Alves
2017-08-23 13:19 ` Sergio Durigan Junior
2017-08-23 18:18 ` Pedro Alves
2017-08-23 18:28 ` Sergio Durigan Junior
2017-09-01 18:33 ` [PATCH v2] [libcc1] Rename C{,P}_COMPILER_NAME and remove triplet from them Sergio Durigan Junior
2017-09-15 4:12 ` Sergio Durigan Junior
2017-09-26 16:53 ` Sergio Durigan Junior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lgmahq7p.fsf@redhat.com \
--to=sergiodj@redhat.com \
--cc=aoliva@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=keiths@redhat.com \
--cc=pmuldoon@redhat.com \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox