Bug 198151 - /usr/include/sys/elf64.h macro ELF64_R_INFO needs a cast
Summary: /usr/include/sys/elf64.h macro ELF64_R_INFO needs a cast
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 9.1-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs mailing list
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2015-03-02 10:30 UTC by jphartmann
Modified: 2017-04-23 18:29 UTC (History)
0 users

See Also:


Attachments
Trivial test case (964 bytes, text/plain)
2015-03-02 10:30 UTC, jphartmann
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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