Page MenuHomeFreeBSD

Fix new -Werror compiler warnings in binutils
ClosedPublic

Authored by arichardson on Nov 3 2017, 12:36 PM.
Tags
None
Referenced Files
F105700444: D12928.id36967.diff
Thu, Dec 19, 9:32 AM
Unknown Object (File)
Tue, Dec 10, 11:50 AM
Unknown Object (File)
Nov 19 2024, 4:35 PM
Unknown Object (File)
Nov 16 2024, 1:14 AM
Unknown Object (File)
Nov 3 2024, 6:29 PM
Unknown Object (File)
Nov 3 2024, 6:29 PM
Unknown Object (File)
Nov 3 2024, 6:29 PM
Unknown Object (File)
Nov 3 2024, 6:29 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.