- // Add padding zeros to the end of the buffer to make sure that the
- // function will start on the correct byte alignment within the section.
- OutputBuffer OB(*OutBuffer,
- TM.getTargetData()->getPointerSizeInBits() == 64,
- TM.getTargetData()->isLittleEndian());
- OB.align(Align);
- FnStart = OutBuffer->size();
+ // Round the size up to the correct alignment for starting the new function.
+ ES->Size = (ES->Size + (Align-1)) & (-Align);
+
+ // Snaity check on allocated space for text section
+ assert( ES->Size < 4096 && "no more space in TextSection" );
+
+ // FIXME: Using ES->Size directly here instead of calculating it from the
+ // output buffer size (impossible because the code emitter deals only in raw
+ // bytes) forces us to manually synchronize size and write padding zero bytes
+ // to the output buffer for all non-text sections. For text sections, we do
+ // not synchonize the output buffer, and we just blow up if anyone tries to
+ // write non-code to it. An assert should probably be added to
+ // AddSymbolToSection to prevent calling it on the text section.
+ CurBufferPtr = BufferBegin + ES->Size;
+
+ // Record function start address relative to BufferBegin
+ FnStartPtr = CurBufferPtr;