Skip to content

Instantly share code, notes, and snippets.

@sapphire-arches
Last active October 14, 2023 21:50
Show Gist options
  • Save sapphire-arches/45fc6d3c57b569247173dc7fb3eb6e22 to your computer and use it in GitHub Desktop.
Save sapphire-arches/45fc6d3c57b569247173dc7fb3eb6e22 to your computer and use it in GitHub Desktop.
MCVE for ARM mode ODR violation
#include "a.hpp"
A::~A() { }
#pragma once
class A {
public:
A();
virtual ~A();
};
arm-none-eabi-gcc -x c++ -o main.o -c -Wall -flto -ffunction-sections -mthumb-interwork -mcpu=cortex-a9 -O2 -mfpu=neon -marm main.cpp
arm-none-eabi-gcc -x c++ -o a.o -c -Wall -flto -ffunction-sections -mthumb-interwork -mcpu=cortex-a9 -O2 -mfpu=neon -mthumb a.cpp
arm-none-eabi-gcc -o main --specs=nano.specs --specs=rdimon.specs -Wall -flto -ffunction-sections -mthumb-interwork -mcpu=cortex-a9 -O2 -mfpu=neon main.o a.o
a.hpp:5:7: warning: type 'struct A' violates the C++ One Definition Rule [-Wodr]
5 | class A {
| ^
a.hpp:5:7: note: a type with different virtual table pointers is defined in another translation unit
5 | class A {
| ^
#include "a.hpp"
int main(int argc, char const * const * argv) {
A a;
}
CFLAGS=-Wall -flto -ffunction-sections -mthumb-interwork -mcpu=cortex-a9 -O2 -mfpu=neon
main: main.o a.o
arm-none-eabi-gcc -o $@ --specs=nano.specs --specs=rdimon.specs $(CFLAGS) $^
a.o: a.cpp
arm-none-eabi-gcc -x c++ -o $@ -c $(CFLAGS) -mthumb $<
main.o: main.cpp
arm-none-eabi-gcc -x c++ -o $@ -c $(CFLAGS) -marm $<
.PHONY: clean
clean:
rm -f *.o
rm -f main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment