Skip to content

Instantly share code, notes, and snippets.

@scriptum
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scriptum/57ae4d2524d42fccb494 to your computer and use it in GitHub Desktop.
Save scriptum/57ae4d2524d42fccb494 to your computer and use it in GitHub Desktop.
LTO gcc test
#include "a.hpp"
#include "stdio.h"
void A::set(int a, int b)
{
x = a;
y = b;
}
void A::get()
{
printf("%d %d\n", x, y);
}
class A {
private:
int x, y;
public:
void set(int a, int b);
void get();
};
#include "a.hpp"
int main()
{
A a;
a.set(10, 15);
a.get();
}
g++ -c -O2 -flto -g test.cpp a.cpp && g++ -O2 -g test.o a.o
objdump -S a.out | grep 'int main' -A15
# Optimized output:
#
# int main()
# {
# 400550: 48 83 ec 08 sub $0x8,%rsp
# x = a;
# y = b;
# }
# void A::get()
# {
# printf("%d %d\n", x, y);
# 400554: ba 0f 00 00 00 mov $0xf,%edx
# 400559: be 0a 00 00 00 mov $0xa,%esi
# 40055e: bf 04 07 40 00 mov $0x400704,%edi
# 400563: 31 c0 xor %eax,%eax
# 400565: e8 b6 ff ff ff callq 400520 <printf@plt>
# A a;
# a.set(10,15);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment