Open Bug 1048227 Opened 12 years ago Updated 4 years ago

Linker removes symbols and links against the wrong methods

Categories

(Firefox Build System :: General, defect)

ARM
Gonk (Firefox OS)
defect

Tracking

(Not tracked)

People

(Reporter: tzimmermann, Unassigned)

References

Details

Attachments

(2 files)

We have several classes with the name |ConnectResultHandler| in - dom/bluetooth/bluedroid/BluetoothSocket.cpp, - dom/bluetooth/bluedroid/BluetoothA2dpManager.cpp, and - dom/bluetooth/bluedroid/hfp/BluetoothHfpManager.cpp. STR: - (revert patch [02] from bug 1045486), - build B2G with Bluedroid, - run 'nm $(OBJDIR)/dom/bluetooth/BluetoothSocket.o' - search symbols with 'ConnectResultHandler' - run 'nm $(OBJDIR)/dist/sdk/lib/libxul.so' - search symbols with 'ConnectResultHandler' Expected: - symbols from BluetoothSocket.o exist in libxul.so Actual result: - only the symbols from BluetoothHfpManager.o exist Each class only exists in its source file and is not present in any headers. I'm not sure if this is allowed behavior or a bug in the linker, but we should not allow this to happen IMHO.
(In reply to Thomas Zimmermann [:tzimmermann] [:tdz] from comment #0) > Each class only exists in its source file and is not present in any headers. > I'm not sure if this is allowed behavior or a bug in the linker, but we > should not allow this to happen IMHO. You might be able to use the gold linker's --detect-odr-violations (not sure if that'll be a warning or a full error).
A simple workaround would be to wrap each class in an anonymous namespace. It's possible that declaring them static might also help. (I also don't know enough to say if this behavior makes sense by the standard or not.)
For fixing bug 1045486, I simply renamed the class in BluetoothSocket.cpp. The problem is rather that it took two people two days to figure out what's going on. We should be able to find such problems much easier if we could have at least a warning from the linker.
(In reply to Ted Mielczarek [:ted.mielczarek] from comment #2) > A simple workaround would be to wrap each class in an anonymous namespace. > It's possible that declaring them static might also help. (I also don't know > enough to say if this behavior makes sense by the standard or not.) if I'm understanding the complaint right this is perfectly valid per the standard and for that matter more or less required to implement C++ (at least the merging symbols with the same name part).
According to WP, [1] the linker's behavior is correct. But it would be good to get (at least) a warning when the linker removes duplicated symbols that refer to different pieces of code. As I said, it took us two days to figure this out. With a warning we would probably have solved this within a few minutes. [1] https://en.wikipedia.org/wiki/One_Definition_Rule#Summary
(In reply to Thomas Zimmermann [:tzimmermann] [:tdz] from comment #5) > As I said, it took us two days to figure this out. With a warning we would > probably have solved this within a few minutes. Do b2g builds use gold? That's the only linker (AFAICT) that will complain about this (MSVC might, but I can't find a comprehensive list of what warnings the linker can emit), and I don't know that it will complain about your particular case.
This quick hack turns on gold's --detect-odr-violations; it seems to DTRT for me with --enable-gold on my local Linux build. I'm not setup to do b2g builds, though. Thomas, could you see if this would have warned about your issue? (I'm told that b2g builds use gold by default, but if that's not true, you may have to pass --enable-gold to configure.)
Attachment #8468465 - Flags: feedback?(tzimmermann)
Attached file odr-violations.txt —
Hi Nathan, Thanks for taking a closer look at the problem. I built with the patch applied and got ODR warnings from gold. But there are too many for practical use. I guess most of them are false positives.
Attachment #8468465 - Flags: feedback?(tzimmermann) → feedback+
Product: Core → Firefox Build System
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: