Recent

Author Topic: How To Disable RTTI ?  (Read 10626 times)

Eko Wahyudin

  • New Member
  • *
  • Posts: 21
  • Indonesia
How To Disable RTTI ?
« on: January 27, 2012, 08:42:36 am »
Hi,

I'm try to make simple kernel like on http://wiki.osdev.org/Pascal_Bare_Bones

but I don't want RTTI information on my kernel. I do not used it, It's wasting space.

so, How to disable RTTI on FPC ?

------------
I'm add  {$TYPEINFO OFF} on every single file.
but still not working
------------
note: on the attachment, the red font is RTTI data.

thx
« Last Edit: January 27, 2012, 11:30:26 am by Eko Wahyudin »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11980
  • FPC developer.
Re: How To Disable RTTI ?
« Reply #1 on: January 27, 2012, 09:37:40 am »
Do not use RTTI types. So classes derived from tpersistent or enums.

typeinfo is off by default for classes, but classes that inherit from types that are RTTId are rttied themselves.

Enums are afaik always RTTId

Eko Wahyudin

  • New Member
  • *
  • Posts: 21
  • Indonesia
Re: How To Disable RTTI ?
« Reply #2 on: January 27, 2012, 11:24:06 am »
I'm not using RTTI types, or a class type. I'm just using primitive types like integer, longInt, cardinal, pchar and packed record.

but (as you can see on the attachment) at ".data" section, string of "integer", "longInt", "shortInt", "cardinal" ,"ansiString", "pchar", etc and all record name, included in the binary executable.

Laksen

  • Hero Member
  • *****
  • Posts: 786
    • J-Software
Re: How To Disable RTTI ?
« Reply #3 on: January 27, 2012, 11:40:41 am »
Try adding --gc-sections, and -s to the ld command line

Eko Wahyudin

  • New Member
  • *
  • Posts: 21
  • Indonesia
Re: How To Disable RTTI ?
« Reply #4 on: January 27, 2012, 02:08:46 pm »
by adding -s to ld, debug information is gone. but RTTI data still exist. I have try that before.

add --gc-sections, has no effect.
« Last Edit: January 27, 2012, 02:55:28 pm by Eko Wahyudin »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11980
  • FPC developer.
Re: How To Disable RTTI ?
« Reply #5 on: January 27, 2012, 03:03:10 pm »
1. What FPC are you using,
2. what settings (parameters)
3. where is an example program that we can compile?

I _can_ imagine that in Delphi/objfpc modes the RTTI of the base types is always linked in. But that doesn't explain that you also see record types. (which are afaik never RTTIed, unless that is a recent addition)

You  can compile with -al, and see what references the relevant sections.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11980
  • FPC developer.
Re: How To Disable RTTI ?
« Reply #6 on: January 27, 2012, 03:15:22 pm »
--gc-sections probably only works if you add -XX -CX to the FPC flags.

If I do that, I drop from 19k to 14k. But there is still a block of what looks like label names at the end. If I manually strip the object files though, stuff goes horribly wrong.

So I added -s to the linker, and presto, it worked.  12k, and not much in there.

My script: (files as on the website you referenced, no modifications)

Code: [Select]
#!/bin/sh

rm *.o *.ppu
fpc -Aelf -n -O3 -Op3 -Si -Sc -Sg -Xd -Rintel -Tlinux kernel.pas -CX -XXs
nasm -f elf stub.asm -o stub.o
ld --gc-sections -s -Tlinker.script -o kernel.obj stub.o kernel.o multiboot.o system.o console.o

If you (or sb else) has an osdev account, and can edit, please add this to that link. Thank you.
« Last Edit: January 27, 2012, 03:20:27 pm by marcov »

Eko Wahyudin

  • New Member
  • *
  • Posts: 21
  • Indonesia
Re: How To Disable RTTI ?
« Reply #7 on: January 28, 2012, 12:31:26 am »
Woow It's work ...  thanks a lot markov :)

now RTTI symbol in .data section has gone. The label at the and is section name, it's natural in ELF file format.

Code: [Select]
00002000  00 00 00 00 46 72 65 65  70 61 73 63 61 6c 20 62  |....Freepascal b|
00002010  61 72 65 62 6f 6e 65 20  4f 53 20 62 6f 6f 74 65  |arebone OS boote|
00002020  64 21 00 90 48 61 6c 74  69 6e 67 20 73 79 73 74  |d!..Halting syst|
00002030  65 6d 2c 20 61 20 6d 75  6c 74 69 62 6f 6f 74 2d  |em, a multiboot-|
00002040  63 6f 6d 70 6c 69 61 6e  74 20 62 6f 6f 74 20 6c  |compliant boot l|
00002050  6f 61 64 65 72 20 6e 65  65 64 65 64 21 00 89 f6  |oader needed!...|
00002060  42 6f 6f 74 65 64 20 62  79 20 61 20 6d 75 6c 74  |Booted by a mult|
00002070  69 62 6f 6f 74 2d 63 6f  6d 70 6c 69 61 6e 74 20  |iboot-compliant |
00002080  62 6f 6f 74 20 6c 6f 61  64 65 72 21 00 8d 76 00  |boot loader!..v.|
00002090  4d 75 6c 74 69 62 6f 6f  74 20 69 6e 66 6f 72 6d  |Multiboot inform|
000020a0  61 74 69 6f 6e 3a 00 90  20 20 20 20 20 20 20 20  |ation:..        |
000020b0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 4c  |               L|
000020c0  6f 77 65 72 20 6d 65 6d  6f 72 79 20 20 3d 20 00  |ower memory  = .|
000020d0  4b 42 00 90 20 20 20 20  20 20 20 20 20 20 20 20  |KB..            |
000020e0  20 20 20 20 20 20 20 20  20 20 20 48 69 67 68 65  |           Highe|
000020f0  72 20 6d 65 6d 6f 72 79  20 3d 20 00 20 20 20 20  |r memory = .    |
00002100  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00002110  20 20 20 54 6f 74 61 6c  20 6d 65 6d 6f 72 79 20  |   Total memory |
00002120  20 3d 20 00 4d 42 00 00  00 00 00 00 00 00 00 00  | = .MB..........|
00002130  00 00 00 00 00 00 00 00  00 00 00 00 00 80 0b 00  |................|
00002140  00 00 10 00 00 10 10 00  00 20 10 00 00 60 10 00  |......... ...`..|
00002150  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

« Last Edit: January 28, 2012, 12:43:06 am by Eko Wahyudin »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8783
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How To Disable RTTI ?
« Reply #8 on: January 29, 2012, 01:20:37 am »
Quote
If you (or sb else) has an osdev account, and can edit, please add this to that link. Thank you.
Done, please check whether I give the correct info or not.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11980
  • FPC developer.
Re: How To Disable RTTI ?
« Reply #9 on: January 29, 2012, 12:52:25 pm »
Quote
If you (or sb else) has an osdev account, and can edit, please add this to that link. Thank you.
Done, please check whether I give the correct info or not.

Small remarks:

- I don't know if -XX is necessary (since linker cmdline is not construct by compiler. It probably causes the --gc-sections to be added when the compiler calls the linker)
- The rtti got out with smartlinking, the -s removes debug info (*). For some reason, stripping the .o's with strip doesn't work properly, so we let the linker do it.

(*) which were the "record types" RTTI that Eko saw. They were labels wrt debuginfo, not true RTTI. The base RTTI for basic types is linked in always, but can be removed by smartlinking if unused (not referenced by RTTI of classes that can't be smartlinked)
« Last Edit: January 29, 2012, 12:54:15 pm by marcov »

 

TinyPortal © 2005-2018