[Bug 198151] /usr/include/sys/elf64.h macro ELF64_R_INFO needs a cast

bugzilla-noreply at freebsd.org bugzilla-noreply at freebsd.org
Mon Mar 2 10:30:53 UTC 2015


https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=198151

            Bug ID: 198151
           Summary: /usr/include/sys/elf64.h macro ELF64_R_INFO needs a
                    cast
           Product: Base System
           Version: 9.1-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: freebsd-bugs at FreeBSD.org
          Reporter: jphartmann at gmail.com

Created attachment 153658
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=153658&action=edit
Trivial test case

https://svnweb.freebsd.org/base/head/sys/sys/elf64.h?revision=276539&view=markup

Line 160 in the current SVN:

#define ELF64_R_INFO(sym, type) (((sym) << 32) + ((type) & 0xffffffffL))

This means that sym is not promoted to 64 bit and as a result it is truncated
by the shift.  Gcc 4.2.1 issues a warning about this. 

 cc1: warnings being treated as errors
elf.c: In function 'elfrld':
elf.c:513: warning: left shift count >= width of type

Linux defines the macro as

#define ELF64_R_INFO(sym,type)          ((((Elf64_Xword) (sym)) << 32) +
(type))

[john at fb91 ~/src/z/hlasm]$ gcc --version
gcc (GCC) 4.2.1 20070831 patched [FreeBSD]
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[john at fb91 ~/src/z/hlasm]$ uname -a
FreeBSD fb91.jphartmann.net 9.1-RELEASE-p10 FreeBSD 9.1-RELEASE-p10 #0: Tue Apr
 8 06:17:44 CEST 2014     root at fb91.jphartmann.net:/usr/obj/usr/src/sys/GENERIC
 amd64

Test case in FreeBSD 9.1:

[john at fb91 ~/src/testing]$ gcc ebug.c -o ebug
ebug.c: In function 'main':
ebug.c:25: warning: left shift count >= width of type
[john at fb91 ~/src/testing]$ ./ebug
000000 000000 020000 000000 000000 000000 

Same on Linux:
[/home/john/src/testing] ./ebug
000000 000000 020000 010000 000000 000000

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the freebsd-bugs mailing list