From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 99E5B3888C6B for ; Mon, 22 Aug 2022 00:54:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 99E5B3888C6B Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-617-7ZMDmytHNJO0-ocg35gDgw-1; Sun, 21 Aug 2022 20:54:09 -0400 X-MC-Unique: 7ZMDmytHNJO0-ocg35gDgw-1 Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-334ab1f0247so161083737b3.7 for ; Sun, 21 Aug 2022 17:54:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc; bh=Jn/rTAPl9Ji/RFOxqNP1m7IaJsdqQD4i09QUpuK+Ar8=; b=7g5zvPM+EySO5Km4QegAZAgHX52iiqp4nYLouwJR03kAHEaRtDRWvHtKxxeXm4L6LA OFdJIxfh9pcwBYKXWo1XLMlfJ4vyQl5Xu0o7rgrnngeP+mPRcaJSikA/MXd42PSv7qMU rgMyMDxsDKd/NaUUMapFCBxVBn6SUQwHLYu4vGUYWYHQmJ28GVROVmWsipFeB6Po3vQe su2oWhMVwGm1DQxRqFA9SHHiYRMwTPijufTZndzXcSwsPFIYTSM+JVlZKtrs8genaGYn ZlxfFDeZp4hsVtBz+TQ4aGmCJaF5qt4nZhQ1MJ4fPohxEHZwFZg8lpAmBt4a5NlL0QgM zDhA== X-Gm-Message-State: ACgBeo162JnPlehNrqo+W5URGzLBQavfc53c34omMZmgGmTtOWhnoroj IixD0rVxqE+FiKpTRtd4ZYdwe/mA9DYC9Ie7AA2YJ2HwMCVTDbMu8+qtO47Xmu0To8K/maxdD+W v4dJrr6UDyLtp+Zh5WMS7L8qPm6w2JQ== X-Received: by 2002:a0d:cad1:0:b0:335:8273:e9fd with SMTP id m200-20020a0dcad1000000b003358273e9fdmr18339737ywd.154.1661129648522; Sun, 21 Aug 2022 17:54:08 -0700 (PDT) X-Google-Smtp-Source: AA6agR4oEf1appnzy4mcJwwh6ivO8PtbroC+DYNX8awXAFAGZBDiPhLrieOMveop34hZE+a9psqCi62f9YSXg81Xfrg= X-Received: by 2002:a0d:cad1:0:b0:335:8273:e9fd with SMTP id m200-20020a0dcad1000000b003358273e9fdmr18339725ywd.154.1661129648190; Sun, 21 Aug 2022 17:54:08 -0700 (PDT) MIME-Version: 1.0 From: Reid Wahl Date: Sun, 21 Aug 2022 17:53:57 -0700 Message-ID: Subject: -fno-builtin not preventing __builtin___snprintf_chk in gcc 11.2.0-19ubuntu1 To: gcc-help@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Aug 2022 00:54:13 -0000 Hello, I'm hitting a strange issue with GCC while trying to wrap and mock snprintf() for unit testing purposes. I'm setting -fno-builtin and -fno-inline, but __builtin___snprintf_chk() is getting called instead of snprintf(). The net effect is that my __wrap__snprintf() never gets called. Do you have any advice on how to prevent object size checking builtins from being used, without setting a lower optimization level? I expected -fno-builtin to take care of it. Note that out of my whole multi-distro test bed, I've only observed this issue on Ubuntu 22.04, Ubuntu 20.04, and Fedora 36 Power 9. I don't have direct access to the test machines, but I spun up an Ubuntu 22.04 reproducer. It uses gcc version 11.2.0-19ubuntu1. A known working Fedora 36 x86_64 system uses gcc version 12.1.1 20220507. On that system, snprintf() (or more accurately __wrap_snprintf()) gets called as expected, instead of the builtin. There are also RHEL 7 machines in the testbed, so it works fine on older versions as well. Minimal reproducer: ``` # cat test.c #include void func(const char *s) { char buf[16]; snprintf(buf, 16, "%s", s); printf("%s\n", buf); } int main(void) { func("hello world"); } # gcc -g -O2 -fno-builtin -fno-inline test.c -o test # gdb -q ./test Reading symbols from ./test... (gdb) b 5 Breakpoint 1 at 0x10a0: file test.c, line 9. (gdb) r Starting program: /root/git/pacemaker/test [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Breakpoint 1, main () at test.c:9 9 { (gdb) s 10 func("hello world"); (gdb) func (s=s@entry=0x55555555600b "hello world") at test.c:3 3 { (gdb) 5 snprintf(buf, 16, "%s", s); (gdb) 0x00005555555551b9 in snprintf (__fmt=, __n=, __s=) at /usr/include/x86_64-linux-gnu/bits/stdio2.h:71 71 return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, ``` Thank you. -- Regards, Reid Wahl (He/Him) Senior Software Engineer, Red Hat RHEL High Availability - Pacemaker