r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Red] Red language group

Dockimbel
18-Mar-2011
[499]
(just the program header entries)
Kaj
18-Mar-2011
[500]
I don't think it would be any different than on Linux, but I will
Dockimbel
18-Mar-2011
[501]
Should be 2 lines starting with LOAD.
Kaj
18-Mar-2011
[502]
OK
Dockimbel
18-Mar-2011
[503]
Also, do you know if Syllable requires a "section headers" part in 
executable binaries? (it's optional in ELF specifications)
Kaj
18-Mar-2011
[504x3]
[[kaj-:-syllable]:~/Red]readelf -l empty

                                                                                                                                                                                                        
Elf file type is EXEC (Executable file)
Entry point 0x8048074
There are 2 program headers, starting at offset 52

                                                                                                                                                                                                        
Program Headers:

  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg 
  Align

  LOAD           0x000000 0x08048000 0x08048000 0x00184 0x00184 R E 
  0x1000

  LOAD           0x000184 0x08048184 0x08048184 0x00032 0x00032 RW 
   0x1000
[[kaj-:-syllable]:~/Red]
Indeed, exactly the same as on Linux, as it's the same executable, 
and the same readelf
I have to mention that Syllable does something odd by compiling all 
its own programs as shared libraries, so it could also be a problem 
in our loader that wasn't hit before
Dockimbel
18-Mar-2011
[507x2]
Seems good, sizes are specified, 0x32 (40) for the 2nd segment. Don't 
know what could cause the issue for the image loader, maybe the lack 
of section headers?
oops, 0x32 = 50
Kaj
18-Mar-2011
[509]
I don't know, I'll have to dive into our loader. It's much like Red: 
the minimum we needed over time to get things working :-)
Dockimbel
18-Mar-2011
[510]
AFAIK, shared libraries on Linux have special requirements, like 
for the code, it must be compiled in PIC mode (Postion Independent 
Code). Red/System doesn't support that mode.
Kaj
18-Mar-2011
[511]
Yes, I expect it not to work once loaded, but it doesn't even load 
yet
Dockimbel
18-Mar-2011
[512]
A good opportunity to learn more about Linux kernel hacking. :-)
Kaj
18-Mar-2011
[513x2]
Not really, this is the Syllable kernel :-)
We determined that the shared library trick isn't even necessary, 
so we have a backburner plan to change it. So I hope it will be possible 
to get regular executables to run
Dockimbel
18-Mar-2011
[515]
Btw, PIC mode will have to be supported at some point of Red evolution 
in order to be able to build dynamic libraries for Linux (don't know 
for OS X).
Kaj
18-Mar-2011
[516]
Yep, that will be another impressive addition
Dockimbel
18-Mar-2011
[517]
DLL generation support could be added for Windows without too much 
effort (just by extending the PE.r code), but for Linux, it requires 
both work at the linker and at the compiler level for PIC support.
Kaj
18-Mar-2011
[518x2]
Here's our loader:
http://syllable.cvs.sourceforge.net/viewvc/syllable/syllable/system/sys/kernel/kernel/elf.c?view=markup
Dockimbel
18-Mar-2011
[520x2]
Code looks somehow cleaner and easier to read than the linux loader. 
:-)
Ok it seems it relies on section headers rather than program headers: 

if ( sElfHdr.e_nSecHdrSize != sizeof( Elf32_SectionHeader_s ) )
{

    printk( "Error: load_image() Invalid section size %d, expected %d\n", 
    sElfHdr.e_nSecHdrSize, sizeof( Elf32_SectionHeader_s ) );
    nError = -EINVAL;
    goto error;
}
Andreas
18-Mar-2011
[522]
i think we can add a basic shdr table rather quickly
Dockimbel
18-Mar-2011
[523x2]
nSecHdrSize is at 0 in Red's emitter.
Andreas: yes, it's not a big deal...seems you're volunteering? :-)
Andreas
18-Mar-2011
[525]
i'll at least have a look or two :)
Kaj
18-Mar-2011
[526x2]
That would be cool
readelf gave me the impression that section and program headers are 
the same
Dockimbel
18-Mar-2011
[528]
Program headers describe segments. Segments are composed of one or 
several sections merged together. In our current ELF implementation, 
each segment contains only one section, so headers should be almost 
the same. That will change with the addition of dynamic linking support 
(which seem to require a lot of additional sections).
Kaj
18-Mar-2011
[529x2]
That could be the reason that our loader always expects segment headers, 
because a Syllable program is also a dynamic library
I think we ran into the multiple sections per segment problem halfway 
our development, when we needed to implement it
BrianH
19-Mar-2011
[531x2]
Wouldn't position-independent code be required even on Windows if 
you wanted to support address space layout randomization (ASLR) and 
other such tricks?
It also helps when running Windows code on fake Windows-like OSes 
like SanOS that load at a different address.
Dockimbel
19-Mar-2011
[533x2]
ASLR: I suppose it's required, but I can't find any information from 
an official source explaining the exact requirement for ASLR on Windows 
(except the additional flag to set in the executable header).


While searching for that, I found this interesting reading about 
PIC: http://www.gentoo.org/proj/en/hardened/pic-internals.xml#doc_chap7
I would like, if possible, to support PIC without the additional 
cost of an indirection table for global data.
Andreas
19-Mar-2011
[535x4]
Brian: loading at a different address should not be a problem, for 
that, relocatable code is sufficient. Full ASLR, however, will require 
not only relocatable but position-independent code.
(Take that with a sufficiently sized grain of salt, as I don't know 
anything about how ASLR on Windows works. But I find it hard to imagine 
how they would get away without PIC :)
But at least for PaX-based Linux ELF ASLR, full ASLR requires "position-independent 
executables" (PIE) which are  ELF binaries with a special type flag 
and PIC.
But I guess I wouldn't worry about ASLR for Red at this point :))
Kaj
19-Mar-2011
[539]
Interesting, it sounds like Syllable is prepared for that :-)
Andreas
19-Mar-2011
[540x2]
You have PaX on Syllable?
Some basic ASLR (stack randomisation and mmap-base randomisation) 
was added to the mainline Linux kernel in 2.6.12:
http://lwn.net/Articles/121845/
Kaj
19-Mar-2011
[542]
We don't have PaX, we have PIC executables, as far as I know
Andreas
19-Mar-2011
[543]
Beyond that, full ASLR is still quite rare in Linux, at least as 
far as I know.
Dockimbel
19-Mar-2011
[544]
New revision released: preprocessor replaced by a new one running 
at block-level (so much more accurate now). Includes and simple macros 
are now also possible.
Kaj
19-Mar-2011
[545x2]
Those are some good improvements
Includes make Red a real programming language :-)
Dockimbel
19-Mar-2011
[547]
Well, that's not my intention, but it wouldn't need much to make 
it a C replacement language.
Andreas
20-Mar-2011
[548]
i have a first crude hack of a ELF section header table working. 
it can currently describe itself :)