Bug 198151

Summary: /usr/include/sys/elf64.h macro ELF64_R_INFO needs a cast
Product: Base System Reporter: jphartmann
Component: kernAssignee: freebsd-bugs mailing list <bugs>
Status: New ---    
Severity: Affects Some People Keywords: patch
Priority: ---    
Version: 9.1-RELEASE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Trivial test case none

Description jphartmann 2015-03-02 10:30:53 UTC
Created attachment 153658 [details]
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@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@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@fb91.jphartmann.net:/usr/obj/usr/src/sys/GENERIC  amd64

Test case in FreeBSD 9.1:

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

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