Page MenuHomeFreeBSD

Fix new -Werror compiler warnings in binutils
ClosedPublic

Authored by arichardson on Nov 3 2017, 12:36 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Apr 9, 8:08 PM
Unknown Object (File)
Thu, Mar 28, 3:48 PM
Unknown Object (File)
Mar 7 2024, 4:47 PM
Unknown Object (File)
Feb 11 2024, 6:32 AM
Unknown Object (File)
Jan 13 2024, 2:50 AM
Unknown Object (File)
Dec 26 2023, 11:21 PM
Unknown Object (File)
Dec 20 2023, 6:19 AM
Unknown Object (File)
Nov 18 2023, 3:50 PM
Subscribers

Details

Summary

Latest clang git has a warning -Wnull-pointer-arithmetic which will trigger
a -Werror failure. Addition and subtraction from a null pointer is
undefined behaviour and could be optimized into anything. Furthermore,
using the difference between two pointers and casting the result back to a
pointer is not portable since the size of ptrdiff_t does not necessary
have to be the same as size of void* (this happens e.g. on CHERI). Using
intptr_t instead fixes this portability issue and the compiler warning.

Obtained from: CheriBSD

Test Plan

I can now compile binutils with latest clang HEAD.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

I don't have strong opinions about this - hopefully this code can be fixed by some judicious application of svn rm in the near future...

contrib/binutils/include/obstack.h
116 ↗(On Diff #34712)

C doesn't require that int* and void* have the same representation. On some (very) old machines, loads and stores worked only at the granularity of a machine word (typically 16 bits, though sometimes larger). An int* on such a machine was represented as a (word) address, but a char* might be a pair of an address and a byte offset. Accessing a char required a load an a shift or mask.

I think binutils still supports at least one such architecture (though FreeBSD doesn't).

Generally, I think we lower WARNS on contrib code, especially poor-quality GNU code, though when the fix is this simple it might be worth retaining - especially as binutils is due a de-orbit burn soon and is unlikely to ever receive an update..

I would probably be inclined to just add -Wno-foo to WARNFLAGS.clang with a suitable compiler version check instead if this generates equivalent code for non-CHERI. (For CHERI I think we can just always build ld.bfd as a plain MIPS binary while we still need ld.bfd).

arichardson retitled this revision from Fix new compiler warnings in binutils to Fix new -Werror compiler warnings in binutils.
arichardson added a reviewer: dim.

removed unnecessary comment

I'm going to commit this now, since we need it in the clang600-import branch.

This revision is now accepted and ready to land.Dec 24 2017, 4:48 PM
This revision was automatically updated to reflect the committed changes.