From 9c7a41ea645e33541cb96ad9ef3a4fecc026b721 Mon Sep 17 00:00:00 2001 From: "Reser, Ben" Date: Fri, 4 Mar 2016 15:36:19 -0800 Subject: Add patch for glibc 2.22 for CVE-2015-7547. This resolves a vulnerability related to getaddrinfo(). diff --git a/patches/glibc/2.22/120-cve-2105-7547-getaddrinfo-stack.patch b/patches/glibc/2.22/120-cve-2105-7547-getaddrinfo-stack.patch new file mode 100644 index 0000000..257c5f2 --- /dev/null +++ b/patches/glibc/2.22/120-cve-2105-7547-getaddrinfo-stack.patch @@ -0,0 +1,551 @@ +diff -ruN glibc-2.22.orig/resolv/nss_dns/dns-host.c glibc-2.22/resolv/nss_dns/dns-host.c +--- glibc-2.22.orig/resolv/nss_dns/dns-host.c 2015-08-04 23:42:21.000000000 -0700 ++++ glibc-2.22/resolv/nss_dns/dns-host.c 2016-02-16 13:38:38.000000000 -0800 +@@ -1031,7 +1031,10 @@ + int h_namelen = 0; + + if (ancount == 0) +- return NSS_STATUS_NOTFOUND; ++ { ++ *h_errnop = HOST_NOT_FOUND; ++ return NSS_STATUS_NOTFOUND; ++ } + + while (ancount-- > 0 && cp < end_of_message && had_error == 0) + { +@@ -1208,7 +1211,14 @@ + /* Special case here: if the resolver sent a result but it only + contains a CNAME while we are looking for a T_A or T_AAAA record, + we fail with NOTFOUND instead of TRYAGAIN. */ +- return canon == NULL ? NSS_STATUS_TRYAGAIN : NSS_STATUS_NOTFOUND; ++ if (canon != NULL) ++ { ++ *h_errnop = HOST_NOT_FOUND; ++ return NSS_STATUS_NOTFOUND; ++ } ++ ++ *h_errnop = NETDB_INTERNAL; ++ return NSS_STATUS_TRYAGAIN; + } + + +@@ -1222,11 +1232,101 @@ + + enum nss_status status = NSS_STATUS_NOTFOUND; + ++ /* Combining the NSS status of two distinct queries requires some ++ compromise and attention to symmetry (A or AAAA queries can be ++ returned in any order). What follows is a breakdown of how this ++ code is expected to work and why. We discuss only SUCCESS, ++ TRYAGAIN, NOTFOUND and UNAVAIL, since they are the only returns ++ that apply (though RETURN and MERGE exist). We make a distinction ++ between TRYAGAIN (recoverable) and TRYAGAIN' (not-recoverable). ++ A recoverable TRYAGAIN is almost always due to buffer size issues ++ and returns ERANGE in errno and the caller is expected to retry ++ with a larger buffer. ++ ++ Lastly, you may be tempted to make significant changes to the ++ conditions in this code to bring about symmetry between responses. ++ Please don't change anything without due consideration for ++ expected application behaviour. Some of the synthesized responses ++ aren't very well thought out and sometimes appear to imply that ++ IPv4 responses are always answer 1, and IPv6 responses are always ++ answer 2, but that's not true (see the implemetnation of send_dg ++ and send_vc to see response can arrive in any order, particlarly ++ for UDP). However, we expect it holds roughly enough of the time ++ that this code works, but certainly needs to be fixed to make this ++ a more robust implementation. ++ ++ ---------------------------------------------- ++ | Answer 1 Status / | Synthesized | Reason | ++ | Answer 2 Status | Status | | ++ |--------------------------------------------| ++ | SUCCESS/SUCCESS | SUCCESS | [1] | ++ | SUCCESS/TRYAGAIN | TRYAGAIN | [5] | ++ | SUCCESS/TRYAGAIN' | SUCCESS | [1] | ++ | SUCCESS/NOTFOUND | SUCCESS | [1] | ++ | SUCCESS/UNAVAIL | SUCCESS | [1] | ++ | TRYAGAIN/SUCCESS | TRYAGAIN | [2] | ++ | TRYAGAIN/TRYAGAIN | TRYAGAIN | [2] | ++ | TRYAGAIN/TRYAGAIN' | TRYAGAIN | [2] | ++ | TRYAGAIN/NOTFOUND | TRYAGAIN | [2] | ++ | TRYAGAIN/UNAVAIL | TRYAGAIN | [2] | ++ | TRYAGAIN'/SUCCESS | SUCCESS | [3] | ++ | TRYAGAIN'/TRYAGAIN | TRYAGAIN | [3] | ++ | TRYAGAIN'/TRYAGAIN' | TRYAGAIN' | [3] | ++ | TRYAGAIN'/NOTFOUND | TRYAGAIN' | [3] | ++ | TRYAGAIN'/UNAVAIL | UNAVAIL | [3] | ++ | NOTFOUND/SUCCESS | SUCCESS | [3] | ++ | NOTFOUND/TRYAGAIN | TRYAGAIN | [3] | ++ | NOTFOUND/TRYAGAIN' | TRYAGAIN' | [3] | ++ | NOTFOUND/NOTFOUND | NOTFOUND | [3] | ++ | NOTFOUND/UNAVAIL | UNAVAIL | [3] | ++ | UNAVAIL/SUCCESS | UNAVAIL | [4] | ++ | UNAVAIL/TRYAGAIN | UNAVAIL | [4] | ++ | UNAVAIL/TRYAGAIN' | UNAVAIL | [4] | ++ | UNAVAIL/NOTFOUND | UNAVAIL | [4] | ++ | UNAVAIL/UNAVAIL | UNAVAIL | [4] | ++ ---------------------------------------------- ++ ++ [1] If the first response is a success we return success. ++ This ignores the state of the second answer and in fact ++ incorrectly sets errno and h_errno to that of the second ++ answer. However because the response is a success we ignore ++ *errnop and *h_errnop (though that means you touched errno on ++ success). We are being conservative here and returning the ++ likely IPv4 response in the first answer as a success. ++ ++ [2] If the first response is a recoverable TRYAGAIN we return ++ that instead of looking at the second response. The ++ expectation here is that we have failed to get an IPv4 response ++ and should retry both queries. ++ ++ [3] If the first response was not a SUCCESS and the second ++ response is not NOTFOUND (had a SUCCESS, need to TRYAGAIN, ++ or failed entirely e.g. TRYAGAIN' and UNAVAIL) then use the ++ result from the second response, otherwise the first responses ++ status is used. Again we have some odd side-effects when the ++ second response is NOTFOUND because we overwrite *errnop and ++ *h_errnop that means that a first answer of NOTFOUND might see ++ its *errnop and *h_errnop values altered. Whether it matters ++ in practice that a first response NOTFOUND has the wrong ++ *errnop and *h_errnop is undecided. ++ ++ [4] If the first response is UNAVAIL we return that instead of ++ looking at the second response. The expectation here is that ++ it will have failed similarly e.g. configuration failure. ++ ++ [5] Testing this code is complicated by the fact that truncated ++ second response buffers might be returned as SUCCESS if the ++ first answer is a SUCCESS. To fix this we add symmetry to ++ TRYAGAIN with the second response. If the second response ++ is a recoverable error we now return TRYAGIN even if the first ++ response was SUCCESS. */ ++ + if (anslen1 > 0) + status = gaih_getanswer_slice(answer1, anslen1, qname, + &pat, &buffer, &buflen, + errnop, h_errnop, ttlp, + &first); ++ + if ((status == NSS_STATUS_SUCCESS || status == NSS_STATUS_NOTFOUND + || (status == NSS_STATUS_TRYAGAIN + /* We want to look at the second answer in case of an +@@ -1242,8 +1342,15 @@ + &pat, &buffer, &buflen, + errnop, h_errnop, ttlp, + &first); ++ /* Use the second response status in some cases. */ + if (status != NSS_STATUS_SUCCESS && status2 != NSS_STATUS_NOTFOUND) + status = status2; ++ /* Do not return a truncated second response (unless it was ++ unavoidable e.g. unrecoverable TRYAGAIN). */ ++ if (status == NSS_STATUS_SUCCESS ++ && (status2 == NSS_STATUS_TRYAGAIN ++ && *errnop == ERANGE && *h_errnop != NO_RECOVERY)) ++ status = NSS_STATUS_TRYAGAIN; + } + + return status; +diff -ruN glibc-2.22.orig/resolv/res_query.c glibc-2.22/resolv/res_query.c +--- glibc-2.22.orig/resolv/res_query.c 2015-08-04 23:42:21.000000000 -0700 ++++ glibc-2.22/resolv/res_query.c 2016-02-16 13:38:38.000000000 -0800 +@@ -396,6 +396,7 @@ + { + free (*answerp2); + *answerp2 = NULL; ++ *nanswerp2 = 0; + *answerp2_malloced = 0; + } + } +@@ -447,6 +448,7 @@ + { + free (*answerp2); + *answerp2 = NULL; ++ *nanswerp2 = 0; + *answerp2_malloced = 0; + } + +@@ -521,6 +523,7 @@ + { + free (*answerp2); + *answerp2 = NULL; ++ *nanswerp2 = 0; + *answerp2_malloced = 0; + } + if (saved_herrno != -1) +diff -ruN glibc-2.22.orig/resolv/res_send.c glibc-2.22/resolv/res_send.c +--- glibc-2.22.orig/resolv/res_send.c 2015-08-04 23:42:21.000000000 -0700 ++++ glibc-2.22/resolv/res_send.c 2016-02-16 13:43:59.000000000 -0800 +@@ -1,3 +1,20 @@ ++/* Copyright (C) 2016 Free Software Foundation, Inc. ++ This file is part of the GNU C Library. ++ ++ The GNU C Library is free software; you can redistribute it and/or ++ modify it under the terms of the GNU Lesser General Public ++ License as published by the Free Software Foundation; either ++ version 2.1 of the License, or (at your option) any later version. ++ ++ The GNU C Library 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 ++ Lesser General Public License for more details. ++ ++ You should have received a copy of the GNU Lesser General Public ++ License along with the GNU C Library; if not, see ++ . */ ++ + /* + * Copyright (c) 1985, 1989, 1993 + * The Regents of the University of California. All rights reserved. +@@ -363,6 +380,8 @@ + #ifdef USE_HOOKS + if (__glibc_unlikely (statp->qhook || statp->rhook)) { + if (anssiz < MAXPACKET && ansp) { ++ /* Always allocate MAXPACKET, callers expect ++ this specific size. */ + u_char *buf = malloc (MAXPACKET); + if (buf == NULL) + return (-1); +@@ -638,6 +657,77 @@ + return (struct sockaddr *) (void *) &statp->nsaddr_list[n]; + } + ++/* The send_vc function is responsible for sending a DNS query over TCP ++ to the nameserver numbered NS from the res_state STATP i.e. ++ EXT(statp).nssocks[ns]. The function supports sending both IPv4 and ++ IPv6 queries at the same serially on the same socket. ++ ++ Please note that for TCP there is no way to disable sending both ++ queries, unlike UDP, which honours RES_SNGLKUP and RES_SNGLKUPREOP ++ and sends the queries serially and waits for the result after each ++ sent query. This implemetnation should be corrected to honour these ++ options. ++ ++ Please also note that for TCP we send both queries over the same ++ socket one after another. This technically violates best practice ++ since the server is allowed to read the first query, respond, and ++ then close the socket (to service another client). If the server ++ does this, then the remaining second query in the socket data buffer ++ will cause the server to send the client an RST which will arrive ++ asynchronously and the client's OS will likely tear down the socket ++ receive buffer resulting in a potentially short read and lost ++ response data. This will force the client to retry the query again, ++ and this process may repeat until all servers and connection resets ++ are exhausted and then the query will fail. It's not known if this ++ happens with any frequency in real DNS server implementations. This ++ implementation should be corrected to use two sockets by default for ++ parallel queries. ++ ++ The query stored in BUF of BUFLEN length is sent first followed by ++ the query stored in BUF2 of BUFLEN2 length. Queries are sent ++ serially on the same socket. ++ ++ Answers to the query are stored firstly in *ANSP up to a max of ++ *ANSSIZP bytes. If more than *ANSSIZP bytes are needed and ANSCP ++ is non-NULL (to indicate that modifying the answer buffer is allowed) ++ then malloc is used to allocate a new response buffer and ANSCP and ++ ANSP will both point to the new buffer. If more than *ANSSIZP bytes ++ are needed but ANSCP is NULL, then as much of the response as ++ possible is read into the buffer, but the results will be truncated. ++ When truncation happens because of a small answer buffer the DNS ++ packets header feild TC will bet set to 1, indicating a truncated ++ message and the rest of the socket data will be read and discarded. ++ ++ Answers to the query are stored secondly in *ANSP2 up to a max of ++ *ANSSIZP2 bytes, with the actual response length stored in ++ *RESPLEN2. If more than *ANSSIZP bytes are needed and ANSP2 ++ is non-NULL (required for a second query) then malloc is used to ++ allocate a new response buffer, *ANSSIZP2 is set to the new buffer ++ size and *ANSP2_MALLOCED is set to 1. ++ ++ The ANSP2_MALLOCED argument will eventually be removed as the ++ change in buffer pointer can be used to detect the buffer has ++ changed and that the caller should use free on the new buffer. ++ ++ Note that the answers may arrive in any order from the server and ++ therefore the first and second answer buffers may not correspond to ++ the first and second queries. ++ ++ It is not supported to call this function with a non-NULL ANSP2 ++ but a NULL ANSCP. Put another way, you can call send_vc with a ++ single unmodifiable buffer or two modifiable buffers, but no other ++ combination is supported. ++ ++ It is the caller's responsibility to free the malloc allocated ++ buffers by detecting that the pointers have changed from their ++ original values i.e. *ANSCP or *ANSP2 has changed. ++ ++ If errors are encountered then *TERRNO is set to an appropriate ++ errno value and a zero result is returned for a recoverable error, ++ and a less-than zero result is returned for a non-recoverable error. ++ ++ If no errors are encountered then *TERRNO is left unmodified and ++ a the length of the first response in bytes is returned. */ + static int + send_vc(res_state statp, + const u_char *buf, int buflen, const u_char *buf2, int buflen2, +@@ -647,11 +737,7 @@ + { + const HEADER *hp = (HEADER *) buf; + const HEADER *hp2 = (HEADER *) buf2; +- u_char *ans = *ansp; +- int orig_anssizp = *anssizp; +- // XXX REMOVE +- // int anssiz = *anssizp; +- HEADER *anhp = (HEADER *) ans; ++ HEADER *anhp = (HEADER *) *ansp; + struct sockaddr *nsap = get_nsaddr (statp, ns); + int truncating, connreset, n; + /* On some architectures compiler might emit a warning indicating +@@ -743,6 +829,8 @@ + * Receive length & response + */ + int recvresp1 = 0; ++ /* Skip the second response if there is no second query. ++ To do that we mark the second response as received. */ + int recvresp2 = buf2 == NULL; + uint16_t rlen16; + read_len: +@@ -779,40 +867,14 @@ + u_char **thisansp; + int *thisresplenp; + if ((recvresp1 | recvresp2) == 0 || buf2 == NULL) { ++ /* We have not received any responses ++ yet or we only have one response to ++ receive. */ + thisanssizp = anssizp; + thisansp = anscp ?: ansp; + assert (anscp != NULL || ansp2 == NULL); + thisresplenp = &resplen; + } else { +- if (*anssizp != MAXPACKET) { +- /* No buffer allocated for the first +- reply. We can try to use the rest +- of the user-provided buffer. */ +-#if __GNUC_PREREQ (4, 7) +- DIAG_PUSH_NEEDS_COMMENT; +- DIAG_IGNORE_NEEDS_COMMENT (5, "-Wmaybe-uninitialized"); +-#endif +-#if _STRING_ARCH_unaligned +- *anssizp2 = orig_anssizp - resplen; +- *ansp2 = *ansp + resplen; +-#else +- int aligned_resplen +- = ((resplen + __alignof__ (HEADER) - 1) +- & ~(__alignof__ (HEADER) - 1)); +- *anssizp2 = orig_anssizp - aligned_resplen; +- *ansp2 = *ansp + aligned_resplen; +-#endif +-#if __GNUC_PREREQ (4, 7) +- DIAG_POP_NEEDS_COMMENT; +-#endif +- } else { +- /* The first reply did not fit into the +- user-provided buffer. Maybe the second +- answer will. */ +- *anssizp2 = orig_anssizp; +- *ansp2 = *ansp; +- } +- + thisanssizp = anssizp2; + thisansp = ansp2; + thisresplenp = resplen2; +@@ -820,10 +882,14 @@ + anhp = (HEADER *) *thisansp; + + *thisresplenp = rlen; +- if (rlen > *thisanssizp) { +- /* Yes, we test ANSCP here. If we have two buffers +- both will be allocatable. */ +- if (__glibc_likely (anscp != NULL)) { ++ /* Is the answer buffer too small? */ ++ if (*thisanssizp < rlen) { ++ /* If the current buffer is not the the static ++ user-supplied buffer then we can reallocate ++ it. */ ++ if (thisansp != NULL && thisansp != ansp) { ++ /* Always allocate MAXPACKET, callers expect ++ this specific size. */ + u_char *newp = malloc (MAXPACKET); + if (newp == NULL) { + *terrno = ENOMEM; +@@ -835,6 +901,9 @@ + if (thisansp == ansp2) + *ansp2_malloced = 1; + anhp = (HEADER *) newp; ++ /* A uint16_t can't be larger than MAXPACKET ++ thus it's safe to allocate MAXPACKET but ++ read RLEN bytes instead. */ + len = rlen; + } else { + Dprint(statp->options & RES_DEBUG, +@@ -997,6 +1066,66 @@ + return 1; + } + ++/* The send_dg function is responsible for sending a DNS query over UDP ++ to the nameserver numbered NS from the res_state STATP i.e. ++ EXT(statp).nssocks[ns]. The function supports IPv4 and IPv6 queries ++ along with the ability to send the query in parallel for both stacks ++ (default) or serially (RES_SINGLKUP). It also supports serial lookup ++ with a close and reopen of the socket used to talk to the server ++ (RES_SNGLKUPREOP) to work around broken name servers. ++ ++ The query stored in BUF of BUFLEN length is sent first followed by ++ the query stored in BUF2 of BUFLEN2 length. Queries are sent ++ in parallel (default) or serially (RES_SINGLKUP or RES_SNGLKUPREOP). ++ ++ Answers to the query are stored firstly in *ANSP up to a max of ++ *ANSSIZP bytes. If more than *ANSSIZP bytes are needed and ANSCP ++ is non-NULL (to indicate that modifying the answer buffer is allowed) ++ then malloc is used to allocate a new response buffer and ANSCP and ++ ANSP will both point to the new buffer. If more than *ANSSIZP bytes ++ are needed but ANSCP is NULL, then as much of the response as ++ possible is read into the buffer, but the results will be truncated. ++ When truncation happens because of a small answer buffer the DNS ++ packets header feild TC will bet set to 1, indicating a truncated ++ message, while the rest of the UDP packet is discarded. ++ ++ Answers to the query are stored secondly in *ANSP2 up to a max of ++ *ANSSIZP2 bytes, with the actual response length stored in ++ *RESPLEN2. If more than *ANSSIZP bytes are needed and ANSP2 ++ is non-NULL (required for a second query) then malloc is used to ++ allocate a new response buffer, *ANSSIZP2 is set to the new buffer ++ size and *ANSP2_MALLOCED is set to 1. ++ ++ The ANSP2_MALLOCED argument will eventually be removed as the ++ change in buffer pointer can be used to detect the buffer has ++ changed and that the caller should use free on the new buffer. ++ ++ Note that the answers may arrive in any order from the server and ++ therefore the first and second answer buffers may not correspond to ++ the first and second queries. ++ ++ It is not supported to call this function with a non-NULL ANSP2 ++ but a NULL ANSCP. Put another way, you can call send_vc with a ++ single unmodifiable buffer or two modifiable buffers, but no other ++ combination is supported. ++ ++ It is the caller's responsibility to free the malloc allocated ++ buffers by detecting that the pointers have changed from their ++ original values i.e. *ANSCP or *ANSP2 has changed. ++ ++ If an answer is truncated because of UDP datagram DNS limits then ++ *V_CIRCUIT is set to 1 and the return value non-zero to indicate to ++ the caller to retry with TCP. The value *GOTSOMEWHERE is set to 1 ++ if any progress was made reading a response from the nameserver and ++ is used by the caller to distinguish between ECONNREFUSED and ++ ETIMEDOUT (the latter if *GOTSOMEWHERE is 1). ++ ++ If errors are encountered then *TERRNO is set to an appropriate ++ errno value and a zero result is returned for a recoverable error, ++ and a less-than zero result is returned for a non-recoverable error. ++ ++ If no errors are encountered then *TERRNO is left unmodified and ++ a the length of the first response in bytes is returned. */ + static int + send_dg(res_state statp, + const u_char *buf, int buflen, const u_char *buf2, int buflen2, +@@ -1006,8 +1135,6 @@ + { + const HEADER *hp = (HEADER *) buf; + const HEADER *hp2 = (HEADER *) buf2; +- u_char *ans = *ansp; +- int orig_anssizp = *anssizp; + struct timespec now, timeout, finish; + struct pollfd pfd[1]; + int ptimeout; +@@ -1040,6 +1167,8 @@ + int need_recompute = 0; + int nwritten = 0; + int recvresp1 = 0; ++ /* Skip the second response if there is no second query. ++ To do that we mark the second response as received. */ + int recvresp2 = buf2 == NULL; + pfd[0].fd = EXT(statp).nssocks[ns]; + pfd[0].events = POLLOUT; +@@ -1203,55 +1332,56 @@ + int *thisresplenp; + + if ((recvresp1 | recvresp2) == 0 || buf2 == NULL) { ++ /* We have not received any responses ++ yet or we only have one response to ++ receive. */ + thisanssizp = anssizp; + thisansp = anscp ?: ansp; + assert (anscp != NULL || ansp2 == NULL); + thisresplenp = &resplen; + } else { +- if (*anssizp != MAXPACKET) { +- /* No buffer allocated for the first +- reply. We can try to use the rest +- of the user-provided buffer. */ +-#if _STRING_ARCH_unaligned +- *anssizp2 = orig_anssizp - resplen; +- *ansp2 = *ansp + resplen; +-#else +- int aligned_resplen +- = ((resplen + __alignof__ (HEADER) - 1) +- & ~(__alignof__ (HEADER) - 1)); +- *anssizp2 = orig_anssizp - aligned_resplen; +- *ansp2 = *ansp + aligned_resplen; +-#endif +- } else { +- /* The first reply did not fit into the +- user-provided buffer. Maybe the second +- answer will. */ +- *anssizp2 = orig_anssizp; +- *ansp2 = *ansp; +- } +- + thisanssizp = anssizp2; + thisansp = ansp2; + thisresplenp = resplen2; + } + + if (*thisanssizp < MAXPACKET +- /* Yes, we test ANSCP here. If we have two buffers +- both will be allocatable. */ +- && anscp ++ /* If the current buffer is not the the static ++ user-supplied buffer then we can reallocate ++ it. */ ++ && (thisansp != NULL && thisansp != ansp) + #ifdef FIONREAD ++ /* Is the size too small? */ + && (ioctl (pfd[0].fd, FIONREAD, thisresplenp) < 0 + || *thisanssizp < *thisresplenp) + #endif + ) { ++ /* Always allocate MAXPACKET, callers expect ++ this specific size. */ + u_char *newp = malloc (MAXPACKET); + if (newp != NULL) { +- *anssizp = MAXPACKET; +- *thisansp = ans = newp; ++ *thisanssizp = MAXPACKET; ++ *thisansp = newp; + if (thisansp == ansp2) + *ansp2_malloced = 1; + } + } ++ /* We could end up with truncation if anscp was NULL ++ (not allowed to change caller's buffer) and the ++ response buffer size is too small. This isn't a ++ reliable way to detect truncation because the ioctl ++ may be an inaccurate report of the UDP message size. ++ Therefore we use this only to issue debug output. ++ To do truncation accurately with UDP we need ++ MSG_TRUNC which is only available on Linux. We ++ can abstract out the Linux-specific feature in the ++ future to detect truncation. */ ++ if (__glibc_unlikely (*thisanssizp < *thisresplenp)) { ++ Dprint(statp->options & RES_DEBUG, ++ (stdout, ";; response may be truncated (UDP)\n") ++ ); ++ } ++ + HEADER *anhp = (HEADER *) *thisansp; + socklen_t fromlen = sizeof(struct sockaddr_in6); + assert (sizeof(from) <= fromlen); -- cgit v0.10.2-6-g49f6 From 85af58487290a46e7252504f2af808ad3c99d5d4 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sun, 13 Mar 2016 13:21:31 -0700 Subject: Unbreak powerpc-unknown-linux-uclibc. There is invalid assembly in dmalloc for PowerPC. The issue is that 'stw' expects a memory operand, and =g constraint allows both registers and memory. Newer GCC tends to choose register even at -O0, resulting in invalid assembly. Instead, force a register constraint in 'mflr' and let GCC decide if it wants to store it into memory at all. Reported this upstream. Signed-off-by: Alexey Neyman diff --git a/patches/dmalloc/5.5.2/170-ppc-bogus-assembly.patch b/patches/dmalloc/5.5.2/170-ppc-bogus-assembly.patch new file mode 100644 index 0000000..d92bd8a --- /dev/null +++ b/patches/dmalloc/5.5.2/170-ppc-bogus-assembly.patch @@ -0,0 +1,13 @@ +diff -ur dmalloc-5.5.2.orig/return.h dmalloc-5.5.2/return.h +--- dmalloc-5.5.2.orig/return.h 2016-03-13 13:11:48.090431764 -0700 ++++ dmalloc-5.5.2/return.h 2016-03-13 13:12:11.246642618 -0700 +@@ -251,8 +251,7 @@ + + #define GET_RET_ADDR(file) \ + do { \ +- asm("mflr 0"); \ +- asm("stw 0,%0" : "=g" (file)); \ ++ asm("mflr %0" : "=r"(file)); \ + } while(0) + + #endif /* __powerpc__ && __GNUC__ && !__OPTIMIZE__ */ diff --git a/samples/powerpc-unknown-linux-uclibc/broken b/samples/powerpc-unknown-linux-uclibc/broken deleted file mode 100644 index e69de29..0000000 -- cgit v0.10.2-6-g49f6 From 2c7f7cf84784dd86ce03665a7e65de927e03c23e Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sun, 13 Mar 2016 15:40:57 -0700 Subject: Unbreak *-uclibc with native GDB. Currently, native GDB 7.11 fails to build with uClibc-ng due to undefined reference to _obstack_free. On IRC [http://crosstool-ng.osuosl.org/download/ibot-logs/2016-02-28.html], it has been suggested to disable obstack in uClibc configuration. I think it is a workaround rather than a fix: if another library/app needs obstack, this leaves no viable configuration. IMO, if uClibc seeks to mimic the glibc API, it should also provide _obstack_free call (an alias for which it already has, even though commented out). Signed-off-by: Alexey Neyman diff --git a/patches/uClibc-ng/1.0.12/100-provide-_obstack_free.patch b/patches/uClibc-ng/1.0.12/100-provide-_obstack_free.patch new file mode 100644 index 0000000..9fd4bc3 --- /dev/null +++ b/patches/uClibc-ng/1.0.12/100-provide-_obstack_free.patch @@ -0,0 +1,12 @@ +diff -ur uClibc-ng-1.0.12.orig/libc/misc/gnu/obstack.c uClibc-ng-1.0.12/libc/misc/gnu/obstack.c +--- uClibc-ng-1.0.12.orig/libc/misc/gnu/obstack.c 2016-03-13 15:08:44.408962824 -0700 ++++ uClibc-ng-1.0.12/libc/misc/gnu/obstack.c 2016-03-13 15:13:30.129322998 -0700 +@@ -385,7 +385,7 @@ + abort (); + } + +-# if 0 ++# if 1 + /* Older versions of libc used a function _obstack_free intended to be + called by non-GCC compilers. */ + strong_alias (obstack_free, _obstack_free) -- cgit v0.10.2-6-g49f6 From 62d357d3c0756ec0f220e9cf3a874e591548a65c Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Tue, 15 Mar 2016 11:51:56 -0700 Subject: Unbreak static cross-gdb. GDB's configure mishandles the libexpat.{so,a} libraries when it is given -static in CFLAGS AND --with-libexpat-prefix in configure's args: it checks for /lib/libexpat.so and finding that, attempts to link it as `gcc -static .. conftest.c /lib/libexpat.so`; this obviously fails (.so cannot be statically linked), so configure assumes libexpat is unusable. Thus, --with-libexpat-prefix is dangerous and should be avoided; instead, configure should find the libraries via the supplied CC/LD definitions. diff --git a/scripts/build/debug/300-gdb.sh b/scripts/build/debug/300-gdb.sh index 418e85c..02a8f7e 100644 --- a/scripts/build/debug/300-gdb.sh +++ b/scripts/build/debug/300-gdb.sh @@ -69,7 +69,11 @@ do_debug_gdb_build() { cross_extra_config=("${extra_config[@]}") cross_extra_config+=("--with-expat") - cross_extra_config+=("--with-libexpat-prefix=${CT_HOST_COMPLIBS_DIR}") + # NOTE: DO NOT USE --with-libexpat-prefix (until GDB configure is smarter)!!! + # It conflicts with a static build: GDB's configure script will find the shared + # version of expat and will attempt to link that, despite the -static flag. + # The link will fail, and configure will abort with "expat missing or unusable" + # message. case "${CT_THREADS}" in none) cross_extra_config+=("--disable-threads");; *) cross_extra_config+=("--enable-threads");; @@ -88,11 +92,11 @@ do_debug_gdb_build() { cross_extra_config+=("--disable-nls") fi - CC_for_gdb= - LD_for_gdb= + CC_for_gdb="${CT_HOST}-gcc ${CT_CFLAGS_FOR_HOST} ${CT_LDFLAGS_FOR_HOST}" + LD_for_gdb="${CT_HOST}-ld ${CT_LDFLAGS_FOR_HOST}" if [ "${CT_GDB_CROSS_STATIC}" = "y" ]; then - CC_for_gdb="${CT_HOST}-gcc -static" - LD_for_gdb="${CT_HOST}-ld -static" + CC_for_gdb+=" -static" + LD_for_gdb+=" -static" fi # Disable binutils options when building from the binutils-gdb repo. @@ -162,6 +166,11 @@ do_debug_gdb_build() { fi native_extra_config+=("--with-expat") + # NOTE: DO NOT USE --with-libexpat-prefix (until GDB configure is smarter)!!! + # It conflicts with a static build: GDB's configure script will find the shared + # version of expat and will attempt to link that, despite the -static flag. + # The link will fail, and configure will abort with "expat missing or unusable" + # message. CT_DoLog EXTRA "Configuring native gdb" diff --git a/scripts/crosstool-NG.sh.in b/scripts/crosstool-NG.sh.in index 9297e3b..3c193c3 100644 --- a/scripts/crosstool-NG.sh.in +++ b/scripts/crosstool-NG.sh.in @@ -509,6 +509,8 @@ if [ -z "${CT_RESTART}" ]; then CT_CFLAGS_FOR_HOST+=" ${CT_EXTRA_CFLAGS_FOR_HOST}" CT_LDFLAGS_FOR_HOST= CT_LDFLAGS_FOR_HOST+=" ${CT_EXTRA_LDFLAGS_FOR_HOST}" + CT_CFLAGS_FOR_HOST+=" -I${CT_HOST_COMPLIBS_DIR}/include" + CT_LDFLAGS_FOR_HOST+=" -L${CT_HOST_COMPLIBS_DIR}/lib" CT_DoLog DEBUG "CFLAGS for host compiler: '${CT_CFLAGS_FOR_HOST}'" CT_DoLog DEBUG "LDFLAGS for host compiler: '${CT_LDFLAGS_FOR_HOST}'" -- cgit v0.10.2-6-g49f6 From 7ac327d6c33fa78f194e816beec0796901f5d002 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Tue, 15 Mar 2016 12:23:57 -0700 Subject: Remove --with-expat from extra GDB args. 300-gdb.sh always adds --with-expat, no need to list it in crosstool.config. Signed-off-by: Alexey Neyman diff --git a/samples/aarch64-rpi3-linux-gnueabi/crosstool.config b/samples/aarch64-rpi3-linux-gnueabi/crosstool.config index 7c880c4..2bbece8 100644 --- a/samples/aarch64-rpi3-linux-gnueabi/crosstool.config +++ b/samples/aarch64-rpi3-linux-gnueabi/crosstool.config @@ -11,4 +11,3 @@ CT_BINUTILS_LD_WRAPPER=y CT_BINUTILS_PLUGINS=y CT_CC_LANG_CXX=y CT_DEBUG_gdb=y -CT_GDB_CROSS_EXTRA_CONFIG_ARRAY="--with-expat" diff --git a/samples/aarch64-unknown-linux-gnueabi/crosstool.config b/samples/aarch64-unknown-linux-gnueabi/crosstool.config index 90a2ccc..20b8509 100644 --- a/samples/aarch64-unknown-linux-gnueabi/crosstool.config +++ b/samples/aarch64-unknown-linux-gnueabi/crosstool.config @@ -11,4 +11,3 @@ CT_BINUTILS_LD_WRAPPER=y CT_BINUTILS_PLUGINS=y CT_CC_LANG_CXX=y CT_DEBUG_gdb=y -CT_GDB_CROSS_EXTRA_CONFIG_ARRAY="--with-expat" diff --git a/samples/armv7-rpi2-linux-gnueabihf/crosstool.config b/samples/armv7-rpi2-linux-gnueabihf/crosstool.config index 3c2e478..d56a4f4 100644 --- a/samples/armv7-rpi2-linux-gnueabihf/crosstool.config +++ b/samples/armv7-rpi2-linux-gnueabihf/crosstool.config @@ -12,4 +12,3 @@ CT_BINUTILS_LD_WRAPPER=y CT_BINUTILS_PLUGINS=y CT_CC_LANG_CXX=y CT_DEBUG_gdb=y -CT_GDB_CROSS_EXTRA_CONFIG_ARRAY="--with-expat" diff --git a/samples/armv8-rpi3-linux-gnueabihf/crosstool.config b/samples/armv8-rpi3-linux-gnueabihf/crosstool.config index 2a0ad43..043cc6f 100644 --- a/samples/armv8-rpi3-linux-gnueabihf/crosstool.config +++ b/samples/armv8-rpi3-linux-gnueabihf/crosstool.config @@ -12,4 +12,3 @@ CT_BINUTILS_LD_WRAPPER=y CT_BINUTILS_PLUGINS=y CT_CC_LANG_CXX=y CT_DEBUG_gdb=y -CT_GDB_CROSS_EXTRA_CONFIG_ARRAY="--with-expat" -- cgit v0.10.2-6-g49f6 From 712b617a744aa941b99d32d9ff6d9126c77382fb Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Tue, 15 Mar 2016 12:39:03 -0700 Subject: Unbreak sparc-unknown-linux-gnu. GLIBC 2.23 dropped support for pre-v9 SPARC in pthreads. Pass host triplet with s/sparc/sparcv9/ replacement for 2.23. Signed-off-by: Alexey Neyman diff --git a/config/libc/glibc.in b/config/libc/glibc.in index fc7c85b..96879cc 100644 --- a/config/libc/glibc.in +++ b/config/libc/glibc.in @@ -74,7 +74,7 @@ choice config LIBC_GLIBC_V_2_23 bool prompt "2.23" - select LIBC_GLIBC_2_20_or_later + select LIBC_GLIBC_2_23_or_later config LIBC_GLIBC_V_2_22 bool @@ -109,6 +109,11 @@ endchoice endif # ! LIBC_GLIBC_CUSTOM +# Checked by SPARC build: SPARCv8 is dropped in 2.23. +config LIBC_GLIBC_2_23_or_later + select LIBC_GLIBC_2_20_or_later + bool + # DeMark 2.20 as no longer needs to set NPTL as an addon. # It is no longer possible to build glibc without pthread! config LIBC_GLIBC_2_20_or_later diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index 0a09cbd..013c6eb 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -73,6 +73,7 @@ do_libc_backend() { local multi_dir local multi_flags local extra_dir + local target local libc_headers libc_startfiles libc_full local hdr local arg @@ -136,11 +137,24 @@ do_libc_backend() { CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-${libc_mode}${extra_dir//\//_}" + target=${CT_TARGET} + case "${target}" in + # SPARC quirk: glibc 2.23 and newer dropped support for SPARCv8 and + # earlier (corresponding pthread barrier code is missing). Until this + # support is reintroduced, configure as sparcv9. + sparc-*) + if [ "${CT_LIBC_GLIBC_2_23_or_later}" = y ]; then + target=${target/#sparc-/sparcv9-} + fi + ;; + esac + do_libc_backend_once extra_dir="${extra_dir}" \ extra_flags="${extra_flags}" \ libc_headers="${libc_headers}" \ libc_startfiles="${libc_startfiles}" \ - libc_full="${libc_full}" + libc_full="${libc_full}" \ + target="${target}" CT_Popd @@ -192,6 +206,7 @@ do_libc_backend_once() { local glibc_cflags local float_extra local endian_extra + local target local arg for arg in "$@"; do @@ -341,7 +356,7 @@ do_libc_backend_once() { "${src_dir}/configure" \ --prefix=/usr \ --build=${CT_BUILD} \ - --host=${CT_TARGET} \ + --host=${target} \ --cache-file="$(pwd)/config.cache" \ --without-cvs \ --disable-profile \ -- cgit v0.10.2-6-g49f6 From cc7f7db7676b828ec3f75cea6463e62f44d1c519 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Tue, 15 Mar 2016 18:52:05 -0700 Subject: Mark x86_64-w64-mingw32,x86_64-pc-linux-gnu broken. I couldn't get this sample to build. I tried rolling ct-ng back to 1.22 and back to the commit that introduced it, to no avail. Not sure if it ever built on my machine. The first problem is the failure to build binutils/gold because of the missing in mingw. However, even if CT_BINUTILS_GOLD_THREADS option is unset, the build dies in configure of the pass-1 of the core CC. The config.log states that it failed to link with libmpfr.a, which has a lot of undefined references to symbols like '__imp___iob_func'. Googling shows that these symbols are some dark Cygwin/MinGW magic and I do not have the knowledge of these arcana. Let some other MinGWizard fix it another day. Signed-off-by: Alexey Neyman diff --git a/samples/x86_64-w64-mingw32,x86_64-pc-linux-gnu/broken b/samples/x86_64-w64-mingw32,x86_64-pc-linux-gnu/broken new file mode 100644 index 0000000..e69de29 diff --git a/samples/x86_64-w64-mingw32,x86_64-pc-linux-gnu/crosstool.config b/samples/x86_64-w64-mingw32,x86_64-pc-linux-gnu/crosstool.config index 10ed299..304ad60 100644 --- a/samples/x86_64-w64-mingw32,x86_64-pc-linux-gnu/crosstool.config +++ b/samples/x86_64-w64-mingw32,x86_64-pc-linux-gnu/crosstool.config @@ -1,6 +1,4 @@ CT_EXPERIMENTAL=y -CT_DEBUG_CT=y -CT_DEBUG_CT_SAVE_STEPS=y CT_LOCAL_TARBALLS_DIR="${HOME}/src" CT_SAVE_TARBALLS=y # CT_STRIP_HOST_TOOLCHAIN_EXECUTABLES is not set -- cgit v0.10.2-6-g49f6 From 2162cbbdb7a425505e66f8b65f134c33302324f4 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Wed, 16 Mar 2016 11:41:55 -0700 Subject: Work-around another quirk in GDB configure. Previous fix for cross-gdb broke powerpc-unknown_nofpu-linux-gnu which uses an old GDB (6.8a). That GDB's configure chokes on $CC values with multiple consecutive spaces; see the comment in 300-gdb.sh. Signed-off-by: Alexey Neyman diff --git a/scripts/build/debug/300-gdb.sh b/scripts/build/debug/300-gdb.sh index 02a8f7e..ee4753e 100644 --- a/scripts/build/debug/300-gdb.sh +++ b/scripts/build/debug/300-gdb.sh @@ -99,10 +99,17 @@ do_debug_gdb_build() { LD_for_gdb+=" -static" fi - # Disable binutils options when building from the binutils-gdb repo. - cross_extra_config+=("--disable-binutils") - cross_extra_config+=("--disable-ld") - cross_extra_config+=("--disable-gas") + # Fix up whitespace. Some older GDB releases (e.g. 6.8a) get confused if there + # are multiple consecutive spaces: sub-configure scripts replace them with a + # single space and then complain that $CC value changed from that in + # the master directory. + CC_for_gdb=`echo $CC_for_gdb` + LD_for_gdb=`echo $LD_for_gdb` + + # Disable binutils options when building from the binutils-gdb repo. + cross_extra_config+=("--disable-binutils") + cross_extra_config+=("--disable-ld") + cross_extra_config+=("--disable-gas") CT_DoLog DEBUG "Extra config passed: '${cross_extra_config[*]}'" -- cgit v0.10.2-6-g49f6 From 2b0cc92fab7c20acad9657badc025884a48299fe Mon Sep 17 00:00:00 2001 From: Bryan Hundven Date: Thu, 12 May 2016 11:34:34 -0700 Subject: addToolVersion: Fix syntax issues This issue was reported on github: https://github.com/crosstool-ng/crosstool-ng/issues/378 by: alonbg This is the same addToolVersion.sh change in the zipfile, with minor changes. (whitespace) This closes #378 Signed-off-by: Bryan Hundven diff --git a/scripts/addToolVersion.sh b/scripts/addToolVersion.sh index 3cbf712..806ecca 100755 --- a/scripts/addToolVersion.sh +++ b/scripts/addToolVersion.sh @@ -44,7 +44,7 @@ doHelp() { add experimental obsolete version 2.3.5 and stable current versions 2.6.1 and 2.6.2 to glibc, add stable obsolete version 3.3.3 to gcc: ${myname} --glibc -x -o 2.3.5 -s -c 2.6.1 2.6.2 --gcc -o 3.3.3 - EOF +EOF } # Extract field $3 from version $1 with separator $2 @@ -61,7 +61,7 @@ getVersionField() { # $tool : tool name # $tool_prefix : tool directory prefix # $EXP : set to non empty if experimental, to empty otherwise -# #OBS : set to non empty if obsolete, to empty otherwise +# OBS : set to non empty if obsolete, to empty otherwise # $1 : version string to add addToolVersion() { local version="$1" @@ -124,7 +124,7 @@ addToolVersion() { ver_p=$(getVersionField "${version}" . 3) if [ ${ver_M} -eq 2 -a ${ver_m} -eq 26 ]; then SedExpr1="${SedExpr1}\n select BINUTILS_2_26_or_later" - if [ ${ver_M} -eq 2 -a ${ver_m} -eq 25 -a ${ver_p} -eq 1 ]; then + elif [ ${ver_M} -eq 2 -a ${ver_m} -eq 25 -a ${ver_p} -eq 1 ]; then SedExpr1="${SedExpr1}\n select BINUTILS_2_25_1_or_later" elif [ ${ver_M} -eq 2 -a ${ver_m} -eq 25 -a -z ${ver_p} ]; then SedExpr1="${SedExpr1}\n select BINUTILS_2_25_or_later" @@ -139,7 +139,7 @@ addToolVersion() { ver_M=$(getVersionField "${version}" . 1) ver_m=$(getVersionField "${version}" . 2) ver_p=$(getVersionField "${version}" . 3) - elif [ ${ver_M} -eq 0 -a ${ver_m} -eq 9 -a ${ver_p} -eq 33 ]; then + if [ ${ver_M} -eq 0 -a ${ver_m} -eq 9 -a ${ver_p} -eq 33 ]; then SedExpr1="${SedExpr1}\n select LIBC_UCLIBC_0_9_33_2_or_later" fi ;; -- cgit v0.10.2-6-g49f6 From 5a5fcbe148acf35372ecac145816c3515e6b8839 Mon Sep 17 00:00:00 2001 From: Bryan Hundven Date: Fri, 13 May 2016 11:54:54 -0700 Subject: patches/gcc: Backport fix for building gcc-5 with gcc-6 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69959 ...was observed while trying to build gcc-5.3.0 on latest (at the time of this change) archlinux using gcc-6.1.1. This patch fixes the issue. Signed-off-by: Bryan Hundven diff --git a/patches/gcc/5.3.0/130-build_gcc-5_with_gcc-6.patch b/patches/gcc/5.3.0/130-build_gcc-5_with_gcc-6.patch new file mode 100644 index 0000000..fbab9eb --- /dev/null +++ b/patches/gcc/5.3.0/130-build_gcc-5_with_gcc-6.patch @@ -0,0 +1,151 @@ +From 1e5f1089dec3af328fd03125d6778f666d0bd4e4 Mon Sep 17 00:00:00 2001 +From: edlinger +Date: Thu, 25 Feb 2016 15:33:50 +0000 +Subject: [PATCH 1/1] 2016-02-25 Bernd Edlinger + + Backported from mainline + 2016-02-19 Jakub Jelinek + Bernd Edlinger + + * Make-lang.in: Invoke gperf with -L C++. + * cfns.gperf: Remove prototypes for hash and libc_name_p + inlines. + * cfns.h: Regenerated. + * except.c (nothrow_libfn_p): Adjust. + + +git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-5-branch@233720 138bc75d-0d04-0410-961f-82ee72b054a4 +--- + gcc/cp/Make-lang.in | 2 +- + gcc/cp/cfns.gperf | 10 ++-------- + gcc/cp/cfns.h | 41 ++++++++++++++--------------------------- + gcc/cp/except.c | 3 ++- + 5 files changed, 31 insertions(+), 37 deletions(-) + +diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in +index e98beb1..b09fb02 100644 +--- a/gcc/cp/Make-lang.in ++++ b/gcc/cp/Make-lang.in +@@ -111,7 +111,7 @@ else + # deleting the $(srcdir)/cp/cfns.h file. + $(srcdir)/cp/cfns.h: + endif +- gperf -o -C -E -k '1-6,$$' -j1 -D -N 'libc_name_p' -L ANSI-C \ ++ gperf -o -C -E -k '1-6,$$' -j1 -D -N 'libc_name_p' -L C++ \ + $(srcdir)/cp/cfns.gperf --output-file $(srcdir)/cp/cfns.h + + # +diff --git a/gcc/cp/cfns.gperf b/gcc/cp/cfns.gperf +index 68acd3d..214ecf6 100644 +--- a/gcc/cp/cfns.gperf ++++ b/gcc/cp/cfns.gperf +@@ -1,3 +1,5 @@ ++%language=C++ ++%define class-name libc_name + %{ + /* Copyright (C) 2000-2015 Free Software Foundation, Inc. + +@@ -16,14 +18,6 @@ for more details. + You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING3. If not see + . */ +-#ifdef __GNUC__ +-__inline +-#endif +-static unsigned int hash (const char *, unsigned int); +-#ifdef __GNUC__ +-__inline +-#endif +-const char * libc_name_p (const char *, unsigned int); + %} + %% + # The standard C library functions, for feeding to gperf; the result is used +diff --git a/gcc/cp/cfns.h b/gcc/cp/cfns.h +index 1c6665d..596f413 100644 +--- a/gcc/cp/cfns.h ++++ b/gcc/cp/cfns.h +@@ -1,5 +1,5 @@ +-/* ANSI-C code produced by gperf version 3.0.3 */ +-/* Command-line: gperf -o -C -E -k '1-6,$' -j1 -D -N libc_name_p -L ANSI-C cfns.gperf */ ++/* C++ code produced by gperf version 3.0.4 */ ++/* Command-line: gperf -o -C -E -k '1-6,$' -j1 -D -N libc_name_p -L C++ --output-file cfns.h cfns.gperf */ + + #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \ + && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \ +@@ -28,7 +28,7 @@ + #error "gperf generated tables don't work with this execution character set. Please report a bug to ." + #endif + +-#line 1 "cfns.gperf" ++#line 3 "cfns.gperf" + + /* Copyright (C) 2000-2015 Free Software Foundation, Inc. + +@@ -47,25 +47,18 @@ for more details. + You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING3. If not see + . */ +-#ifdef __GNUC__ +-__inline +-#endif +-static unsigned int hash (const char *, unsigned int); +-#ifdef __GNUC__ +-__inline +-#endif +-const char * libc_name_p (const char *, unsigned int); + /* maximum key range = 391, duplicates = 0 */ + +-#ifdef __GNUC__ +-__inline +-#else +-#ifdef __cplusplus +-inline +-#endif +-#endif +-static unsigned int +-hash (register const char *str, register unsigned int len) ++class libc_name ++{ ++private: ++ static inline unsigned int hash (const char *str, unsigned int len); ++public: ++ static const char *libc_name_p (const char *str, unsigned int len); ++}; ++ ++inline unsigned int ++libc_name::hash (register const char *str, register unsigned int len) + { + static const unsigned short asso_values[] = + { +@@ -122,14 +115,8 @@ hash (register const char *str, register unsigned int len) + return hval + asso_values[(unsigned char)str[len - 1]]; + } + +-#ifdef __GNUC__ +-__inline +-#ifdef __GNUC_STDC_INLINE__ +-__attribute__ ((__gnu_inline__)) +-#endif +-#endif + const char * +-libc_name_p (register const char *str, register unsigned int len) ++libc_name::libc_name_p (register const char *str, register unsigned int len) + { + enum + { +diff --git a/gcc/cp/except.c b/gcc/cp/except.c +index 3ff1ce6..2f2e396 100644 +--- a/gcc/cp/except.c ++++ b/gcc/cp/except.c +@@ -1040,7 +1040,8 @@ nothrow_libfn_p (const_tree fn) + unless the system headers are playing rename tricks, and if + they are, we don't want to be confused by them. */ + id = DECL_NAME (fn); +- return !!libc_name_p (IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id)); ++ return !!libc_name::libc_name_p (IDENTIFIER_POINTER (id), ++ IDENTIFIER_LENGTH (id)); + } + + /* Returns nonzero if an exception of type FROM will be caught by a +-- +1.7.1 -- cgit v0.10.2-6-g49f6 From 08d91d41f3c0bceed264a24920b4daa98fa18b9a Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Thu, 17 Mar 2016 22:54:43 -0700 Subject: musl: config is broken for !EXPERIMENTAL If EXPERIMENTAL is not set, the only choice for version is the set of released versions - currently, 1.1.14. But this only option is disabled because it is also marked EXPERIMENTAL; this leaves no available choices in the configuration. Marking MUSL as experimental: it seems to have header issues which prevent, for example, gdbserver from building. musl copied chunks of ptrace.h code from the kernel into its own headers, which now clash with Linux kernel headers. Manifests at least on SH4 target. Also, musl breaks in powerpc builds: GCC balks at it with "unsupported DEFAULT_LIBC" message. Also, 64-bit powerpc and mips are not supported. So, until someone figures out the dependencies for musl in config/, mark it experimental. Signed-off-by: Alexey Neyman diff --git a/config/libc/musl.in b/config/libc/musl.in index 00d98ea..ff84448 100644 --- a/config/libc/musl.in +++ b/config/libc/musl.in @@ -1,6 +1,7 @@ # musl options ## depends on ! WINDOWS && ! BARE_METAL +## depends on EXPERIMENTAL ## ## select LIBC_SUPPORT_THREADS_NATIVE ## select CC_CORE_PASSES_NEEDED -- cgit v0.10.2-6-g49f6 From a60946eb24430a8b43b8fe6027d32ab17be28111 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Wed, 30 Mar 2016 18:42:30 -0700 Subject: arch/sparc: better default CPU when targetting Linux By default, sparc64-*-linux is configured with -mcpu=v9. However, according to https://sourceware.org/ml/libc-alpha/2005-12/msg00027.html: "There is no Linux sparc64 port that runs on non-UltraSPARC-I+ ISA CPUs." v9 is such a "non-UltraSPARC-I+ ISA CPU", so it makes no sense to default to v9 when targetting Linux. Change the default to ultrasparc, even though it can suboptimally schedule instructions for newer SPARC CPUs. See the pending patch: https://patchwork.ozlabs.org/patch/409424/ Signed-off-by: Alexey Neyman diff --git a/scripts/build/arch/sparc.sh b/scripts/build/arch/sparc.sh index e3e7491..1cf2acf 100644 --- a/scripts/build/arch/sparc.sh +++ b/scripts/build/arch/sparc.sh @@ -2,4 +2,17 @@ CT_DoArchTupleValues() { # That's the only thing to override CT_TARGET_ARCH="sparc${target_bits_64}${CT_ARCH_SUFFIX}" + + # By default, sparc64-*-linux is configured with -mcpu=v9. However, + # according to https://sourceware.org/ml/libc-alpha/2005-12/msg00027.html, + # "There is no Linux sparc64 port that runs on non-UltraSPARC-I+ ISA CPUs." + # There is a patch that would change the default to -mcpu=ultrasparc for + # sparc64-*-linux configuration: https://patchwork.ozlabs.org/patch/409424/ + # but that patch has not been integrated (yet). One concern raised about + # this patch was that -mcpu=ultrasparc can suboptimally schedule instructions + # for newer SPARC CPUs. So, override to -mcpu=ultrasparc and warn the user. + if [ "${CT_KERNEL}" = "linux" -a "${CT_ARCH_64}" = "y" -a -z "${CT_ARCH_CPU}" ]; then + CT_DoLog WARN "Setting CPU to UltraSPARC-I for sparc64-linux. Set CT_ARCH_CPU if a different CPU is desired." + CT_ARCH_WITH_CPU="--with-cpu=ultrasparc" + fi } -- cgit v0.10.2-6-g49f6 From a49e13fb4edeefba406d98754fb0ca04b707ff4c Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sat, 19 Mar 2016 15:56:26 -0700 Subject: sh: require multilib Now that libc backend installs the libraries into the directory reported by gcc as 'multi-os-directory', sh4 libraries are installed into a '!m4' subdirectory. This directory then confuses GNU ld, which assumes the exclamation mark to be a word separator and attempts to link to '/usr/lib' (a directory). However, if multilib is enabled, the default libraries are installed into the [expected] '/usr/lib/./'. This looks like an artifact of SuperH's unique way of specifying the multilibs to be built in GCC (which may list exclusions, starting with '!'). Signed-off-by: Alexey Neyman diff --git a/config/arch/sh.in b/config/arch/sh.in index 68d3120..60de313 100644 --- a/config/arch/sh.in +++ b/config/arch/sh.in @@ -5,6 +5,7 @@ ## select ARCH_USE_MMU ## select ARCH_SUPPORTS_BOTH_ENDIAN ## select ARCH_DEFAULT_LE +## select ARCH_REQUIRES_MULTILIB ## ## help The Super-H architecture, as defined by: ## help http://www.renesas.com/fmwk.jsp?cnt=superh_family_landing.jsp&fp=/products/mpumcu/superh_family/ -- cgit v0.10.2-6-g49f6 From 55879ed1d83ebb72f2ab6cbbd892448c731a7163 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sat, 19 Mar 2016 00:13:52 -0700 Subject: glibc: do not add bogus options If a multilib configuration contains an endianness option, the ${endian_extra} is set to, for example, 'mb' (note, no dash!). It is then added to CFLAGS, resulting in bogus flags like 'mb -mb'. But it is not even needed, as ${extra_flags} already contains the very same option! Found by experimenting with multilibs with different endianness on SH, which still didn't work, but that's another story... Signed-off-by: Alexey Neyman diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index 013c6eb..f8c970d 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -288,12 +288,12 @@ do_libc_backend_once() { |${sed} -r -e '/^(.*[[:space:]])?-(E[BL]|m((big|little)(-endian)?|e?[bl]))([[:space:]].*)?$/!d;' \ -e 's//\2/;' \ )" + # If extra_flags contained an endianness option, no need to add it again. Otherwise, + # add the option from the configuration. case "${endian_extra}" in EB|mbig-endian|mbig|meb|mb) - extra_cc_args="${extra_cc_args} ${endian_extra}" ;; EL|mlittle-endian|mlittle|mel|ml) - extra_cc_args="${extra_cc_args} ${endian_extra}" ;; "") extra_cc_args="${extra_cc_args} ${CT_ARCH_ENDIAN_OPT}" ;; -- cgit v0.10.2-6-g49f6 From a65d8841ec0ceff75a3d5c3795cfb7435a194670 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Wed, 11 Nov 2015 08:14:53 -0800 Subject: Enable multiarch support in pass-1 GCC. By default, it is 'auto' - which means, it is enabled if there are multilibs directories detected in the installation location for libgcc. Thus, it is not detected for pass-1 GCC: the installation location is empty at this point. Signed-off-by: Alexey Neyman diff --git a/scripts/build/cc/100-gcc.sh b/scripts/build/cc/100-gcc.sh index 7085a90..75721db 100644 --- a/scripts/build/cc/100-gcc.sh +++ b/scripts/build/cc/100-gcc.sh @@ -403,10 +403,17 @@ do_gcc_core_backend() { extra_config+=("--with-system-zlib") fi - # Some versions of gcc have a deffective --enable-multilib. - # Since that's the default, only pass --disable-multilib. + # Some versions of gcc have a defective --enable-multilib. + # Since that's the default, only pass --disable-multilib. For multilib, + # also enable multiarch. Without explicit --enable-multiarch, pass-1 + # compiler is configured as multilib/no-multiarch and pass-2/final + # are multilib/multiarch (because gcc autodetects multiarch based on + # multiple instances of crt*.o in the install directory - which do + # not exist in pass-1). if [ "${CT_MULTILIB}" != "y" ]; then extra_config+=("--disable-multilib") + else + extra_config+=("--enable-multiarch") fi CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'" @@ -880,10 +887,12 @@ do_gcc_backend() { extra_config+=("--with-system-zlib") fi - # Some versions of gcc have a deffective --enable-multilib. + # Some versions of gcc have a defective --enable-multilib. # Since that's the default, only pass --disable-multilib. if [ "${CT_MULTILIB}" != "y" ]; then extra_config+=("--disable-multilib") + else + extra_config+=("--enable-multiarch") fi CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'" -- cgit v0.10.2-6-g49f6 From aa30d0bc4fdf6480a5a24c69e5537f8c41011470 Mon Sep 17 00:00:00 2001 From: Ray Donnelly Date: Fri, 11 Jul 2014 13:39:24 +0100 Subject: gcc: Add --with-multilib-list option Written by Bryan Hundven. Modified by Alexey Neyman to actually add the option to gcc.in. Signed-off-by: Bryan Hundven Signed-off-by: Ray Donnelly Signed-off-by: Alexey Neyman diff --git a/config/cc/gcc.in.2 b/config/cc/gcc.in.2 index 17b41cc..c200d22 100644 --- a/config/cc/gcc.in.2 +++ b/config/cc/gcc.in.2 @@ -37,6 +37,16 @@ config CC_GCC_EXTRA_CONFIG_ARRAY if they are properly quoted (or escaped, but prefer quotes). Eg.: --with-foo="1st arg with 4 spaces" --with-bar=2nd-arg-without-space +config CC_GCC_MULTILIB_LIST + string + prompt "List of multilib variants" + depends on MULTILIB + help + Architecture-specific option of expanding or restricting the list of + the multilib variants to be built. Refer to GCC installation manual + for the format of this option for a particular architecture. + Leave empty to use the default list for this architecture. + config CC_GCC_TARGET_FINAL bool prompt "Use the default targets all and install for the final compiler" diff --git a/scripts/build/cc/100-gcc.sh b/scripts/build/cc/100-gcc.sh index 75721db..7bb3610 100644 --- a/scripts/build/cc/100-gcc.sh +++ b/scripts/build/cc/100-gcc.sh @@ -414,6 +414,9 @@ do_gcc_core_backend() { extra_config+=("--disable-multilib") else extra_config+=("--enable-multiarch") + if [ -n "${CT_CC_GCC_MULTILIB_LIST}" ]; then + extra_config+=("--with-multilib-list=${CT_CC_GCC_MULTILIB_LIST}") + fi fi CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'" @@ -893,6 +896,9 @@ do_gcc_backend() { extra_config+=("--disable-multilib") else extra_config+=("--enable-multiarch") + if [ -n "${CT_CC_GCC_MULTILIB_LIST}" ]; then + extra_config+=("--with-multilib-list=${CT_CC_GCC_MULTILIB_LIST}") + fi fi CT_DoLog DEBUG "Extra config passed: '${extra_config[*]}'" -- cgit v0.10.2-6-g49f6 From 34ecc718d9d2ea7d391056733d004c68fe7e4bf3 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sat, 21 May 2016 13:16:52 -0700 Subject: arch/all: Add common function to return multilib target This code was abstracted out of Cody P Schafer's multilib patch. It doesn't seem right having architecture dependent code in a specific libc implementation script. So this patch breaks it out into scripts/build/arch/.sh in a function: multilib_target_to_build="$(CT_DoArchMultilibTarget 'multi_flags' 'target-in')" Note that this function gets called on each multilib variant with different sets of compiler flags supplied in 'multi_flags'. The caller will first filter the flags so that there is no conflicting flags (e.g., no '-m32 -m64') supplied. Changed by Alexey Neyman: - make option analysis check specific option rather than match global options string as a whole. Moreover, old code did not handle multiple options in the same multilib, e.g. '-m64 -mlittle'. - fixed substitutions in powerpc.sh (*le variants did not match the pattern in the shell parameter expansion) - make s390.sh actually apply the flags it gathered from the options. - straighten the spaghetti in x86.sh by setting two flags, arch & abi. Also, do not depend on "gnu" being the last part - we can have '*-uclibcx32', for example. Signed-off-by: Bryan Hundven Signed-off-by: Ray Donnelly Signed-off-by: Alexey Neyman diff --git a/scripts/build/arch/alpha.sh b/scripts/build/arch/alpha.sh index cf6d40d..ffceae3 100644 --- a/scripts/build/arch/alpha.sh +++ b/scripts/build/arch/alpha.sh @@ -4,3 +4,14 @@ CT_DoArchTupleValues () { # The architecture part of the tuple: CT_TARGET_ARCH="${CT_ARCH}${CT_ARCH_SUFFIX:-${CT_ARCH_ALPHA_VARIANT}}" } + +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +CT_DoArchMultilibTarget () +{ + local target="${1}"; shift + local -a multi_flags=( "$@" ) + + echo "${target}" +} diff --git a/scripts/build/arch/arm.sh b/scripts/build/arch/arm.sh index 5f6ce2f..338392c 100644 --- a/scripts/build/arch/arm.sh +++ b/scripts/build/arch/arm.sh @@ -39,3 +39,14 @@ CT_DoArchTupleValues() { CT_TARGET_SYS="${CT_TARGET_SYS}hf" fi } + +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +CT_DoArchMultilibTarget () +{ + local target="${1}"; shift + local -a multi_flags=( "$@" ) + + echo "${target}" +} diff --git a/scripts/build/arch/m68k.sh b/scripts/build/arch/m68k.sh index bf26d1b..a6eb010 100644 --- a/scripts/build/arch/m68k.sh +++ b/scripts/build/arch/m68k.sh @@ -3,3 +3,14 @@ CT_DoArchTupleValues() { : } + +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +CT_DoArchMultilibTarget () +{ + local target="${1}"; shift + local -a multi_flags=( "$@" ) + + echo "${target}" +} diff --git a/scripts/build/arch/microblaze.sh b/scripts/build/arch/microblaze.sh index 456a6e3..93ecc9a 100644 --- a/scripts/build/arch/microblaze.sh +++ b/scripts/build/arch/microblaze.sh @@ -19,3 +19,14 @@ CT_DoArchTupleValues () { esac } + +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +CT_DoArchMultilibTarget () +{ + local target="${1}"; shift + local -a multi_flags=( "$@" ) + + echo "${target}" +} diff --git a/scripts/build/arch/mips.sh b/scripts/build/arch/mips.sh index 4d732be..68ad4fa 100644 --- a/scripts/build/arch/mips.sh +++ b/scripts/build/arch/mips.sh @@ -14,3 +14,14 @@ CT_DoArchTupleValues() { CT_ARCH_ABI_CFLAG="-mabi=${CT_ARCH_mips_ABI}" CT_ARCH_WITH_ABI="--with-abi=${CT_ARCH_mips_ABI}" } + +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +CT_DoArchMultilibTarget () +{ + local target="${1}"; shift + local -a multi_flags=( "$@" ) + + echo "${target}" +} diff --git a/scripts/build/arch/powerpc.sh b/scripts/build/arch/powerpc.sh index fbc3120..77bbc8a 100644 --- a/scripts/build/arch/powerpc.sh +++ b/scripts/build/arch/powerpc.sh @@ -26,3 +26,44 @@ CT_DoArchTupleValues () { CT_ARCH_CC_EXTRA_CONFIG="--enable-e500_double" fi } +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +CT_DoArchMultilibTarget () +{ + local target="${1}"; shift + local -a multi_flags=( "$@" ) + + local m32=false + local m64=false + local mlittle=false + local mbig=false + + for m in "${multi_flags[@]}"; do + case "$m" in + -m32) m32=true ;; + -m64) m64=true ;; + -mbig) mbig=true ;; + -mlittle) mlittle=true ;; + esac + done + + # Fix up bitness + case "${target}" in + powerpc-*) $m64 && target=${target/#powerpc-/powerpc64-} ;; + powerpcle-*) $m64 && target=${target/#powerpcle-/powerpc64le-} ;; + powerpc64-*) $m32 && target=${target/#powerpc64-/powerpc-} ;; + powerpc64le-*) $m32 && target=${target/#powerpc64le-/powerpcle-} ;; + esac + + # Fix up endianness + case "${target}" in + powerpc-*) $mlittle && target=${target/#powerpc-/powerpcle-} ;; + powerpcle-*) $mbig && target=${target/#powerpcle-/powerpc-} ;; + powerpc64-*) $mlittle && target=${target/#powerpc64-/powerpc64le-} ;; + powerpc64le-*) $mbig && target=${target/#powerpc64le-/powerpc64-} ;; + esac + + # return the target + echo "${target}" +} diff --git a/scripts/build/arch/s390.sh b/scripts/build/arch/s390.sh index b4b8078..e303420 100644 --- a/scripts/build/arch/s390.sh +++ b/scripts/build/arch/s390.sh @@ -6,3 +6,30 @@ CT_DoArchTupleValues() { CT_TARGET_ARCH="s390x${CT_ARCH_SUFFIX}" fi } + +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +CT_DoArchMultilibTarget () +{ + local target="${1}"; shift + local -a multi_flags=( "$@" ) + + local m31=false + local m64=false + + for m in "${multi_flags[@]}"; do + case "${multi_flags}" in + -m64) m64=true ;; + -m31) m31=true ;; + esac + done + + # Fix bitness + case "${target}" in + s390-*) $m64 && target=${target/#s390-/s390x-} ;; + s390x-*) $m31 && target=${target/#s390x-/s390-} ;; + esac + + echo "${target}" +} diff --git a/scripts/build/arch/sh.sh b/scripts/build/arch/sh.sh index 7780e40..e7f4f1a 100644 --- a/scripts/build/arch/sh.sh +++ b/scripts/build/arch/sh.sh @@ -35,3 +35,14 @@ CT_DoArchTupleValues () { esac CT_ARCH_FLOAT_CFLAG= } + +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +CT_DoArchMultilibTarget () +{ + local target="${1}"; shift + local -a multi_flags=( "$@" ) + + echo "${target}" +} diff --git a/scripts/build/arch/sparc.sh b/scripts/build/arch/sparc.sh index 1cf2acf..2d3baa3 100644 --- a/scripts/build/arch/sparc.sh +++ b/scripts/build/arch/sparc.sh @@ -16,3 +16,14 @@ CT_DoArchTupleValues() { CT_ARCH_WITH_CPU="--with-cpu=ultrasparc" fi } + +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +CT_DoArchMultilibTarget () +{ + local target="${1}"; shift + local -a multi_flags=( "$@" ) + + echo "${target}" +} diff --git a/scripts/build/arch/x86.sh b/scripts/build/arch/x86.sh index 69407db..fd7852e 100644 --- a/scripts/build/arch/x86.sh +++ b/scripts/build/arch/x86.sh @@ -21,3 +21,39 @@ CT_DoArchTupleValues() { fi CT_TARGET_ARCH="${CT_TARGET_ARCH}${CT_ARCH_SUFFIX}" } + +#------------------------------------------------------------------------------ +# Get multilib architecture-specific target +# Usage: CT_DoArchMultilibTarget "multilib flags" "target tuple" +CT_DoArchMultilibTarget () +{ + local target="${1}"; shift + local -a multi_flags=( "$@" ) + + local bit32=false + local bit64=false + local abi_dflt=false + local abi_x32=false + + for m in "${multi_flags[@]}"; do + case "$m" in + -m32) bit32=true; abi_dflt=true;; + -m64) bit64=true; abi_dflt=true;; + -mx32) bit64=true; abi_x32=true;; + esac + done + + # Fix up architecture. + case "${target}" in + x86_64-*) $bit32 && target=${target/#x86_64-/i386-} ;; + i[34567]86-*) $bit64 && target=${target/#i[34567]86-/x86_64-} ;; + esac + + # Fix up the ABI part. + case "${target}" in + *x32) $abi_dflt && target=${target/%x32} ;; + *) $abi_x32 && target=${target}x32 ;; + esac + + echo "${target}" +} -- cgit v0.10.2-6-g49f6 From 67b314a05156f9af221b807d543030ef9f0dc842 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sat, 21 May 2016 13:19:42 -0700 Subject: arch/x86: add a sanity check i[34567]86-*-gnux32 is not a valid tuple. Signed-off-by: Bryan Hundven Signed-off-by: Ray Donnelly Signed-off-by: Alexey Neyman diff --git a/scripts/build/arch/x86.sh b/scripts/build/arch/x86.sh index fd7852e..ca0f08b 100644 --- a/scripts/build/arch/x86.sh +++ b/scripts/build/arch/x86.sh @@ -20,6 +20,17 @@ CT_DoArchTupleValues() { esac fi CT_TARGET_ARCH="${CT_TARGET_ARCH}${CT_ARCH_SUFFIX}" + + # Shouldn't be possible to specify this (CT_TARGET_SYS is not specified by the user, + # it is computed by scripts/functions from libc choices). But trap if such invalid + # values ever come from the caller: + case "${CT_TARGET_ARCH}-${CT_TARGET_SYS}" in + i[34567]86-gnux32) + CT_DoLog ERROR "Invalid CT_TARGET: i[34567]86---gnux32 is invalid." + CT_DoLog ERROR "CT_TARGET: ${CT_TARGET}" + CT_Abort "Go read: https://wiki.debian.org/Multiarch/Tuples" + ;; + esac } #------------------------------------------------------------------------------ -- cgit v0.10.2-6-g49f6 From c7da54edf4c2e3a3eb97eb5fb967143e5071a670 Mon Sep 17 00:00:00 2001 From: Ray Donnelly Date: Sat, 12 Apr 2014 13:16:52 +0100 Subject: glibc: Use common arch call to get multilib targets The previous patch added the function 'CT_DoMultilibTarget()' to scripts/build/arch/*.sh. This patch calls the common function to (currently) get just the target tuple for the current multilib target. This patch was originally by: Cody P Schafer Changed by Alexey Neyman: first, try `gcc -print-multiarch`. If it is supported, use whatever it reports. Otherwise, fall back to our guesswork. Move "i486" quirk into glibc.sh, as it is specific to glibc (e.g. uclibc will need i386, which is what GCC reports). Signed-off-by: Bryan Hundven Signed-off-by: Ray Donnelly Signed-off-by: Alexey Neyman diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index f8c970d..192a005 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -137,7 +137,7 @@ do_libc_backend() { CT_mkdir_pushd "${CT_BUILD_DIR}/build-libc-${libc_mode}${extra_dir//\//_}" - target=${CT_TARGET} + target=$( CT_DoMultilibTarget "${CT_TARGET}" ${extra_flags} ) case "${target}" in # SPARC quirk: glibc 2.23 and newer dropped support for SPARCv8 and # earlier (corresponding pthread barrier code is missing). Until this @@ -147,6 +147,18 @@ do_libc_backend() { target=${target/#sparc-/sparcv9-} fi ;; + # x86 quirk: architecture name is i386, but glibc expects i[4567]86 - to + # indicate the desired optimization. If it was a multilib variant of x86_64, + # then it targets at least NetBurst a.k.a. i786, but we'll follow arch/x86.sh + # and set the optimization to i686. Otherwise, replace with the most + # conservative choice, i486. + i386-*) + if [ "${CT_TARGET_ARCH}" = "x86_64" ]; then + target=${target/#i386-/i686-} + else + target=${target/#i386-/i486-} + fi + ;; esac do_libc_backend_once extra_dir="${extra_dir}" \ @@ -193,6 +205,7 @@ do_libc_backend() { # libc_full : Build full libc : bool : n # extra_flags : Extra CFLAGS to use (for multilib) : string : (empty) # extra_dir : Extra subdir for multilib : string : (empty) +# target : Build libc using this target (for multilib) : string : ${CT_TARGET} do_libc_backend_once() { local libc_headers local libc_startfiles @@ -213,6 +226,10 @@ do_libc_backend_once() { eval "${arg// /\\ }" done + if [ "${target}" = "" ]; then + target="${CT_TARGET}" + fi + CT_DoLog EXTRA "Configuring C library" case "${CT_LIBC}" in diff --git a/scripts/functions b/scripts/functions index 70c1ba6..62d264e 100644 --- a/scripts/functions +++ b/scripts/functions @@ -1305,6 +1305,25 @@ CT_DoBuildTargetTuple() { CT_ARCH_TARGET_LDFLAGS="${CT_ARCH_TARGET_LDFLAGS} ${CT_ARCH_ENDIAN_LDFLAG}" } +# This function determines the target tuple for a given set of compiler +# flags, using either GCC's multiarch feature (if supported; if not, +# GCC prints nothing and exits with status 0), falling back to calling +# the architecture-specific functions. +CT_DoMultilibTarget() { + local target="$1"; shift + local -a multi_flags=( "$@" ) + local gcc_multiarch + + gcc_multiarch=$( "${CT_TARGET}-gcc" -print-multiarch "${multi_flags[@]}" ) + if [ -n "${gcc_multiarch}" ]; then + echo "${gcc_multiarch}" + return + fi + + # Fall back to arch-specific guesswork + CT_DoArchMultilibTarget "${target}" "${multi_flags[@]}" +} + # This function does pause the build until the user strikes "Return" # Usage: CT_DoPause [optional_message] CT_DoPause() { -- cgit v0.10.2-6-g49f6 From dc8f2d1c04258069101e913d22c898298b98384c Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Sat, 21 May 2016 16:53:19 -0700 Subject: glibc.sh: build dummy libc.so with correct extra flags Signed-off-by: Alexey Neyman diff --git a/scripts/build/libc/glibc.sh b/scripts/build/libc/glibc.sh index 192a005..472acad 100644 --- a/scripts/build/libc/glibc.sh +++ b/scripts/build/libc/glibc.sh @@ -475,7 +475,8 @@ do_libc_backend_once() { # However, since we will never actually execute its code, # it doesn't matter what it contains. So, treating '/dev/null' # as a C source file, we produce a dummy 'libc.so' in one step - CT_DoExecLog ALL "${cross_cc}" -nostdlib \ + CT_DoExecLog ALL "${cross_cc}" ${extra_flags} \ + -nostdlib \ -nostartfiles \ -shared \ -x c /dev/null \ -- cgit v0.10.2-6-g49f6