[SERVER-10576] Use --detect-odr-violation if linking with a supported linker Created: 19/Aug/13  Updated: 05/Apr/17  Resolved: 29/Nov/16

Status: Closed
Project: Core Server
Component/s: Build
Affects Version/s: None
Fix Version/s: 3.5.1

Type: Improvement Priority: Major - P3
Reporter: Mathias Stearn Assignee: Andrew Morrow (Inactive)
Resolution: Done Votes: 0
Labels: build-planning
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Platforms 2017-01-23
Participants:

 Description   

ODR = One definition rule. This would detect if there were two classes or functions with the same name in the same namespace even if they are never both included in the same translation unit.

Currently this flag is only supported by gold although other linkers may have similar flags. Actual flag to be added to LINKFLAGS is:

"-Wl,--detect-odr-violations".



 Comments   
Comment by Githook User [ 29/Nov/16 ]

Author:

{u'username': u'acmorrow', u'name': u'Andrew Morrow', u'email': u'acm@mongodb.com'}

Message: SERVER-10576 Use gold ODR violation detection if available
Branch: master
https://github.com/mongodb/mongo/commit/075b474c44f5ca9e266b70da201242270d73ba5e

Comment by Andrew Morrow (Inactive) [ 07/Apr/16 ]

I just tried building with -Wl,--detect-odr-violation, and gold crashes. This is on Ubuntu 15.10, so this is pretty recent. Perhaps this feature isn't quite ready.

Comment by Mathias Stearn [ 10/Aug/15 ]

acm, yes, since I think we should have it on by default. At the very least, one of the evergreen builders should be run with this flag so we fail the build on ODR violations.

FYI, I tried adding that to my scons alias, but it is currently failing apparently due to forward declaring StatusWith. I can't tell if this is a false positive or not, but since it stops once it finds the first duplicate, I can't tell how many other errors it may be masking:

Linking build/cached/mongo/mongod
/bin/ld.gold: warning: while linking build/cached/mongo/mongod: symbol 'mongo::StatusWith<mongo::VersionType>::~StatusWith()' defined in multiple places (possible ODR violation):
  src/mongo/s/catalog/catalog_manager.h:61 from build/cached/mongo/s/catalog/replset/catalog_manager_replica_set.o
  src/mongo/s/catalog/type_collection.h:43 from build/cached/mongo/s/catalog/legacy/config_upgrade.o

Comment by Andrew Morrow (Inactive) [ 10/Aug/15 ]

redbeard0531 - Do you think this is still useful, now that you can say:

LINKFLAGS="-fuse-ld=gold -Wl,--detect-odr-violations"

in your ~/.scons/site_scons/mongo_custom_variables.py file?

Comment by Andrew Morrow (Inactive) [ 04/Nov/13 ]

We don't yet have an analogue for AddToCXXFlagsIfSupported for linker flags, but that is how this should be done

  • Create a test body that is an empty mainline
  • Use TryLink to build and link the test body with "-Wl,<flag>".
  • If the TryLink succeeds, add flag to LINKFLAGS.
Generated at Thu Feb 08 03:23:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.