From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 3CDB93870849 for ; Thu, 3 Sep 2020 10:13:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3CDB93870849 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=mittosystems.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=jozef.l@mittosystems.com Received: by mail-wm1-x329.google.com with SMTP id c19so5031084wmd.1 for ; Thu, 03 Sep 2020 03:13:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mittosystems.com; s=google; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition; bh=6WgdDBFLwBHOelvGGO8v7Se1+r0lSbHm14mR2HaLxQs=; b=TJnOAipd38epkSxIiqNBX2zrDp7Q1iJbR32iGVTcLXJEi8ZGAw9CTa5ksfjLtX9NYz EpYNuXuujzn2Hb5FsQsraOyQsXdV76I1jy+LJj1y5lqidV6F+Ax8dNdl3oJNPQIeHlJO Hh/y/LwO9tFqT8x/SnW35ZHoHmsPiHGm7fAMQGm7xkMFx0bJ/Awe/Ff9QaNd/RS00Wbv DPFS+3WeWHyEdiZGl20vWxb8eLkyDGWULFnX2yohVkLI8PgfAotfSPii4Xypp0SkpOq5 vOuxCd5A9hHS9hMEYknIrTchrSyW03bA5orhl2NR1QjWjpwpxV3R1sve1c8Y0rz6JeJB 5jQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :mime-version:content-disposition; bh=6WgdDBFLwBHOelvGGO8v7Se1+r0lSbHm14mR2HaLxQs=; b=luO4YLkP5B9iksSNTKb1dLQtanv/Qxl6Pq4+7GTdkGZqZnqRquBfvtMCFb/Kqf2pJy gRtnwKSTE0qfCZ2AO74QiEx0DQ12woJ/ZXf3rzDo6P8FOVCr/Dgz30Cgb0b8LBqlg8k6 6jcl4/R300HtLykI29ejMt1Yu0g83Ns70w9nde2SvIpucPfGH3gPwo/y7yDT0TN5Daag 6z4TX1mLbgZ1Js/j7g26SaCPjY1gIXOWssNbIjEfiulYqS+z+x3TAjfBC68cf7kDqzFC iuMiXgUNh6SWSjQHsdCqrrVjP0Psyq1Q9hXOvVl6BZwJdjqxbYlirpFqCNi6Rn136DRx Ru+w== X-Gm-Message-State: AOAM533Q+2Tm+U370HXeKutJneIQKzLkgGWwzZoIMdD5m18pFyplxndK 4NHnp1rbmfDb0q3p5kbWfvHwOwT7345IwA== X-Google-Smtp-Source: ABdhPJxv2yrkQohBD5biMcZU4iPn0UBHkwjI/oLt5Muhj/wduqLf9Awjc4DMUNStMwvhpU3jOKwCpQ== X-Received: by 2002:a1c:dd87:: with SMTP id u129mr1707664wmg.172.1599128002941; Thu, 03 Sep 2020 03:13:22 -0700 (PDT) Received: from jozef-acer-manjaro ([2a01:4b00:87fd:900:5e1d:5c99:56da:76e8]) by smtp.gmail.com with ESMTPSA id j14sm3661991wrr.66.2020.09.03.03.13.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 03:13:22 -0700 (PDT) Date: Thu, 3 Sep 2020 11:13:20 +0100 From: Jozef Lawrynowicz To: newlib@sourceware.org Subject: [PATCH] Fix warnings when building for msp430-elf Message-ID: <20200903101320.4mvbhodaqi4bhef4@jozef-acer-manjaro> Mail-Followup-To: newlib@sourceware.org MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="spls4lxrfmixcdwj" Content-Disposition: inline X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Sep 2020 10:13:26 -0000 --spls4lxrfmixcdwj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The MSP430 target supports both 16-bit and 20-bit size_t and intptr_t. Some implicit casts in Newlib expect these types to be "long", (a 32-bit type on MSP430) which causes warnings during compilation such as: "cast from pointer to integer of different size" Successfully regtested the GCC and G++ testsuite for msp430-elf in the default, -mlarge, -mcpu=msp430 and -mlarge/mcode-region=either/-mdata-region=either configurations. These fixes don't actually change any of the testresults. If the patch is acceptable, I would appreciate if someone would commit it for me, as I do not have write access. Thanks, Jozef --spls4lxrfmixcdwj Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-Fix-warnings-when-building-for-msp430-elf.patch" >From ddb84425f54bbcff9531f7230cf2d86db2ae4cde Mon Sep 17 00:00:00 2001 From: Jozef Lawrynowicz Date: Wed, 2 Sep 2020 15:50:07 +0100 Subject: [PATCH] Fix warnings when building for msp430-elf The MSP430 target supports both 16-bit and 20-bit size_t and intptr_t. Some implicit casts in Newlib expect these types to be "long", (a 32-bit type on MSP430) which causes warnings during compilation such as: "cast from pointer to integer of different size" --- libgloss/msp430/sbrk.c | 3 +++ newlib/libc/include/sys/config.h | 4 ++-- newlib/libc/search/db_local.h | 2 +- newlib/libc/search/hcreate_r.c | 5 +++++ newlib/libc/stdio/open_memstream.c | 4 ++-- newlib/libc/stdlib/arc4random.c | 3 ++- newlib/libc/stdlib/nano-mallocr.c | 22 ++++++++++++---------- 7 files changed, 27 insertions(+), 16 deletions(-) diff --git a/libgloss/msp430/sbrk.c b/libgloss/msp430/sbrk.c index 0a88b943a..bbc3fb5ba 100644 --- a/libgloss/msp430/sbrk.c +++ b/libgloss/msp430/sbrk.c @@ -11,6 +11,9 @@ Red Hat, Inc. */ +int write (int fd, const char *buf, int len); +void abort (void); + char * _sbrk (int adj) { diff --git a/newlib/libc/include/sys/config.h b/newlib/libc/include/sys/config.h index d746b15fc..4bc8d29bf 100644 --- a/newlib/libc/include/sys/config.h +++ b/newlib/libc/include/sys/config.h @@ -21,7 +21,7 @@ #endif /* 16 bit integer machines */ -#if defined(__Z8001__) || defined(__Z8002__) || defined(__H8500__) || defined(__W65__) || defined (__mn10200__) || defined (__AVR__) +#if defined(__Z8001__) || defined(__Z8002__) || defined(__H8500__) || defined(__W65__) || defined (__mn10200__) || defined (__AVR__) || defined (__MSP430__) #undef INT_MAX #undef UINT_MAX @@ -162,7 +162,7 @@ #define __SMALL_BITFIELDS #ifdef __MSP430X_LARGE__ -#define _POINTER_INT long +#define _POINTER_INT __int20 #else #define _POINTER_INT int #endif diff --git a/newlib/libc/search/db_local.h b/newlib/libc/search/db_local.h index ba8286657..8167953e8 100644 --- a/newlib/libc/search/db_local.h +++ b/newlib/libc/search/db_local.h @@ -125,7 +125,7 @@ typedef struct { int lorder; /* byte order */ } BTREEINFO; -#define HASHMAGIC 0x061561 +#define HASHMAGIC 0x061561L #define HASHVERSION 2 /* Structure used to pass parameters to the hashing routines. */ diff --git a/newlib/libc/search/hcreate_r.c b/newlib/libc/search/hcreate_r.c index 8aba524ec..400a57f0c 100644 --- a/newlib/libc/search/hcreate_r.c +++ b/newlib/libc/search/hcreate_r.c @@ -72,7 +72,12 @@ SLIST_HEAD(internal_head, internal_entry); * max * sizeof internal_entry must fit into size_t. * assumes internal_entry is <= 32 (2^5) bytes. */ +#ifdef __MSP430X_LARGE__ +/* 20-bit size_t. */ +#define MAX_BUCKETS_LG2 (20 - 1 - 5) +#else #define MAX_BUCKETS_LG2 (sizeof (size_t) * 8 - 1 - 5) +#endif #define MAX_BUCKETS ((size_t)1 << MAX_BUCKETS_LG2) /* Default hash function, from db/hash/hash_func.c */ diff --git a/newlib/libc/stdio/open_memstream.c b/newlib/libc/stdio/open_memstream.c index afa4a6d62..ed71b1cdc 100644 --- a/newlib/libc/stdio/open_memstream.c +++ b/newlib/libc/stdio/open_memstream.c @@ -326,8 +326,8 @@ internal_open_memstream_r (struct _reent *ptr, if (c->max < 64) c->max = 64; #if (SIZE_MAX >= 64 * 1024) - else if (c->max > 64 * 1024) - c->max = 64 * 1024; + else if (c->max > (size_t)64 * 1024) + c->max = (size_t)64 * 1024; #endif *size = 0; *buf = _malloc_r (ptr, c->max); diff --git a/newlib/libc/stdlib/arc4random.c b/newlib/libc/stdlib/arc4random.c index 7632de164..5860d644a 100644 --- a/newlib/libc/stdlib/arc4random.c +++ b/newlib/libc/stdlib/arc4random.c @@ -99,7 +99,8 @@ _rs_stir(void) rs->rs_have = 0; memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf)); - rs->rs_count = (SIZE_MAX <= 65535) ? 65000 : 1600000; + rs->rs_count = (SIZE_MAX <= 65535) ? 65000 + : (SIZE_MAX <= 1048575 ? 1048000 : 1600000); } static inline void diff --git a/newlib/libc/stdlib/nano-mallocr.c b/newlib/libc/stdlib/nano-mallocr.c index 6ba0eb74b..6dbfba84b 100644 --- a/newlib/libc/stdlib/nano-mallocr.c +++ b/newlib/libc/stdlib/nano-mallocr.c @@ -106,8 +106,10 @@ #define sbrk_start __malloc_sbrk_start #define current_mallinfo __malloc_current_mallinfo -#define ALIGN_TO(size, align) \ - (((size) + (align) -1L) & ~((align) -1L)) +#define ALIGN_PTR(ptr, align) \ + (((ptr) + (align) - (intptr_t)1) & ~((align) - (intptr_t)1)) +#define ALIGN_SIZE(size, align) \ + (((size) + (align) - (size_t)1) & ~((align) - (size_t)1)) /* Alignment of allocated block */ #define MALLOC_ALIGN (8U) @@ -214,7 +216,7 @@ static void* sbrk_aligned(RARG malloc_size_t s) if (p == (void *)-1) return p; - align_p = (char*)ALIGN_TO((unsigned long)p, CHUNK_ALIGN); + align_p = (char*)ALIGN_PTR((uintptr_t)p, CHUNK_ALIGN); if (align_p != p) { /* p is not aligned, ask for a few more bytes so that we have s @@ -239,7 +241,7 @@ void * nano_malloc(RARG malloc_size_t s) malloc_size_t alloc_size; - alloc_size = ALIGN_TO(s, CHUNK_ALIGN); /* size of aligned data load */ + alloc_size = ALIGN_SIZE(s, CHUNK_ALIGN); /* size of aligned data load */ alloc_size += MALLOC_PADDING; /* padding */ alloc_size += CHUNK_OFFSET; /* size of chunk head */ alloc_size = MAX(alloc_size, MALLOC_MINCHUNK); @@ -305,7 +307,7 @@ void * nano_malloc(RARG malloc_size_t s) ptr = (char *)r + CHUNK_OFFSET; - align_ptr = (char *)ALIGN_TO((unsigned long)ptr, MALLOC_ALIGN); + align_ptr = (char *)ALIGN_PTR((uintptr_t)ptr, MALLOC_ALIGN); offset = align_ptr - ptr; if (offset) @@ -578,16 +580,16 @@ void * nano_memalign(RARG size_t align, size_t s) if ((align & (align-1)) != 0) return NULL; align = MAX(align, MALLOC_ALIGN); - ma_size = ALIGN_TO(MAX(s, MALLOC_MINSIZE), CHUNK_ALIGN); + ma_size = ALIGN_SIZE(MAX(s, MALLOC_MINSIZE), CHUNK_ALIGN); size_with_padding = ma_size + align - MALLOC_ALIGN; allocated = nano_malloc(RCALL size_with_padding); if (allocated == NULL) return NULL; chunk_p = get_chunk_from_ptr(allocated); - aligned_p = (char *)ALIGN_TO( - (unsigned long)((char *)chunk_p + CHUNK_OFFSET), - (unsigned long)align); + aligned_p = (char *)ALIGN_PTR( + (uintptr_t)((char *)chunk_p + CHUNK_OFFSET), + (uintptr_t)align); offset = aligned_p - ((char *)chunk_p + CHUNK_OFFSET); if (offset) @@ -642,6 +644,6 @@ void * nano_valloc(RARG size_t s) #ifdef DEFINE_PVALLOC void * nano_pvalloc(RARG size_t s) { - return nano_valloc(RCALL ALIGN_TO(s, MALLOC_PAGE_ALIGN)); + return nano_valloc(RCALL ALIGN_SIZE(s, MALLOC_PAGE_ALIGN)); } #endif /* DEFINE_PVALLOC */ -- 2.28.0 --spls4lxrfmixcdwj--