<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: 'Calibri'; COLOR: #000000">
<DIV>cpukit/include/rtems/rtl/rtl-obj-comp.h</DIV>
<DIV>cpukit/libdl/rtl-obj-comp.c</DIV>
<DIV>cpukit/libdl/rtl-rap.c</DIV>
<DIV> </DIV>
<DIV>diff -Naur cpukit/include/rtl/rtl-obj-comp.h 
cpukit_patched/include/rtl/rtl-obj-comp.h</DIV>
<DIV>--- cpukit/include/rtl/rtl-obj-comp.h    2018-10-22 15:05:16 
+0400</DIV>
<DIV>+++ cpukit_patched/include/rtl/rtl-obj-comp.h    2019-02-15 
16:46:26 +0400</DIV>
<DIV>@@ -39,6 +39,7 @@</DIV>
<DIV>  */</DIV>
<DIV>#define RTEMS_RTL_COMP_NONE (0)</DIV>
<DIV>#define RTEMS_RTL_COMP_LZ77 (1)</DIV>
<DIV>+#define RTEMS_RTL_COMP_ZLIB (2)</DIV>
<DIV> </DIV>
<DIV>/**</DIV>
<DIV>  * The compressed file.</DIV>
<DIV> </DIV>
<DIV>diff -Naur cpukit/libdl/rtl-obj-comp.c 
cpukit_patched/libdl/rtl-obj-comp.c</DIV>
<DIV>--- libdl/rtl-obj-comp.c    2018-10-22 15:05:18 +0400</DIV>
<DIV>+++ libdl_patched/rtl-obj-comp.c    2019-02-21 14:08:27 
+0400</DIV>
<DIV>@@ -28,8 +28,19 @@</DIV>
<DIV> </DIV>
<DIV>#include "fastlz.h"</DIV>
<DIV> </DIV>
<DIV>+#include <zlib.h></DIV>
<DIV>+</DIV>
<DIV>#include <stdio.h></DIV>
<DIV> </DIV>
<DIV>+static unsigned write_z;</DIV>
<DIV>+static unsigned have_z;</DIV>
<DIV>+static unsigned char *in_z;</DIV>
<DIV>+static unsigned char *out_z;</DIV>
<DIV>+static unsigned char *ptr_in;</DIV>
<DIV>+static unsigned char *ptr_out;</DIV>
<DIV>+static z_stream strm;</DIV>
<DIV>+static bool start;</DIV>
<DIV>+</DIV>
<DIV>bool</DIV>
<DIV>rtems_rtl_obj_comp_open (rtems_rtl_obj_comp* comp,</DIV>
<DIV>                          
size_t              
size)</DIV>
<DIV>@@ -46,7 +57,23 @@</DIV>
<DIV>     rtems_rtl_set_error (ENOMEM, "no memory for 
compressor buffer");</DIV>
<DIV>     return false;</DIV>
<DIV>   }</DIV>
<DIV>+  in_z = rtems_rtl_alloc_new(RTEMS_RTL_ALLOC_OBJECT, size, 
false);</DIV>
<DIV>+  if (!in_z) </DIV>
<DIV>+  {</DIV>
<DIV>+   rtems_rtl_set_error(ENOMEM, "no memory for compressor 
buffer");</DIV>
<DIV>+   rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, 
comp->buffer);</DIV>
<DIV>+   return false;</DIV>
<DIV>+  }</DIV>
<DIV>+  out_z = rtems_rtl_alloc_new(RTEMS_RTL_ALLOC_OBJECT, comp->size * 
3, false);</DIV>
<DIV>+  if (!out_z) </DIV>
<DIV>+  {</DIV>
<DIV>+   rtems_rtl_set_error(ENOMEM, "no memory for compressor 
buffer");</DIV>
<DIV>+   rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, 
comp->buffer);</DIV>
<DIV>+   rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, in_z);</DIV>
<DIV>+  return false;</DIV>
<DIV>+  }</DIV>
<DIV>   comp->read = 0;</DIV>
<DIV>+  start = true;</DIV>
<DIV>   return true;</DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV>@@ -54,6 +81,10 @@</DIV>
<DIV>rtems_rtl_obj_comp_close (rtems_rtl_obj_comp* comp)</DIV>
<DIV>{</DIV>
<DIV>   rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, 
comp->buffer);</DIV>
<DIV>+  rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, out_z);</DIV>
<DIV>+  rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, in_z);</DIV>
<DIV>+  if (comp->compression == RTEMS_RTL_COMP_ZLIB)</DIV>
<DIV>+   (void) inflateEnd(&strm);</DIV>
<DIV>   comp->cache = NULL;</DIV>
<DIV>   comp->fd = -1;</DIV>
<DIV>   comp->compression = RTEMS_RTL_COMP_LZ77;</DIV>
<DIV>@@ -61,6 +92,7 @@</DIV>
<DIV>   comp->size = 0;</DIV>
<DIV>   comp->offset = 0;</DIV>
<DIV>   comp->read = 0;</DIV>
<DIV>+  start = true;</DIV>
<DIV>}</DIV>
<DIV> </DIV>
<DIV>void</DIV>
<DIV>@@ -70,6 +102,12 @@</DIV>
<DIV>                         
int                  
compression,</DIV>
<DIV>                         
off_t                
offset)</DIV>
<DIV>{</DIV>
<DIV>+  if (!start)</DIV>
<DIV>+  {</DIV>
<DIV>+   start = true;</DIV>
<DIV>+   if (compression == RTEMS_RTL_COMP_ZLIB)</DIV>
<DIV>+    (void) inflateEnd(&strm);</DIV>
<DIV>+   }</DIV>
<DIV>   comp->cache = cache;</DIV>
<DIV>   comp->fd = fd;</DIV>
<DIV>   comp->compression = compression;</DIV>
<DIV>@@ -77,13 +115,13 @@</DIV>
<DIV>   comp->level = 0;</DIV>
<DIV>   comp->read = 0;</DIV>
<DIV>}</DIV>
<DIV>-</DIV>
<DIV>bool</DIV>
<DIV>rtems_rtl_obj_comp_read (rtems_rtl_obj_comp* comp,</DIV>
<DIV>                          
void*               
buffer,</DIV>
<DIV>                          
size_t              
length)</DIV>
<DIV>{</DIV>
<DIV>   uint8_t* bin = buffer;</DIV>
<DIV>+  int ret_z;</DIV>
<DIV> </DIV>
<DIV>   if (!comp->cache)</DIV>
<DIV>   {</DIV>
<DIV>@@ -126,25 +164,32 @@</DIV>
<DIV>       size_t   in_length = sizeof 
(block_size);</DIV>
<DIV>       int      
decompressed;</DIV>
<DIV> </DIV>
<DIV>-      if (!rtems_rtl_obj_cache_read 
(comp->cache, comp->fd, comp->offset,</DIV>
<DIV>-                                     
(void**) &input, &in_length))</DIV>
<DIV>-        return false;</DIV>
<DIV>-</DIV>
<DIV>-      block_size = (input[0] << 8) | 
input[1];</DIV>
<DIV>-</DIV>
<DIV>-      comp->offset += sizeof 
(block_size);</DIV>
<DIV>+      block_size = length > 2048 ? 2048 : 
length;</DIV>
<DIV>+            </DIV>
<DIV>+      if (comp->compression == 
RTEMS_RTL_COMP_LZ77)</DIV>
<DIV>+      {</DIV>
<DIV>+        if 
(!rtems_rtl_obj_cache_read(comp->cache, comp->fd,</DIV>
<DIV>+            
comp->offset, (void**) &input, &in_length))</DIV>
<DIV>+          return false;</DIV>
<DIV>+        block_size = (input[0] << 
8) | input[1];</DIV>
<DIV>+        comp->offset += 
sizeof(block_size);</DIV>
<DIV>+      }</DIV>
<DIV> </DIV>
<DIV>       in_length = block_size;</DIV>
<DIV> </DIV>
<DIV>-      if (!rtems_rtl_obj_cache_read 
(comp->cache, comp->fd, comp->offset,</DIV>
<DIV>-                                     
(void**) &input, &in_length))</DIV>
<DIV>-        return false;</DIV>
<DIV>-</DIV>
<DIV>-      if (in_length != block_size)</DIV>
<DIV>+      if ((comp->compression == 
RTEMS_RTL_COMP_NONE) || </DIV>
<DIV>+          
(comp->compression == RTEMS_RTL_COMP_LZ77)) </DIV>
<DIV>       {</DIV>
<DIV>-        rtems_rtl_set_error (EIO, 
"compressed read failed: bs=%u in=%zu",</DIV>
<DIV>-                             
block_size, in_length);</DIV>
<DIV>-        return false;</DIV>
<DIV>+        if 
(!rtems_rtl_obj_cache_read(comp->cache, comp->fd,</DIV>
<DIV>+            
comp->offset, (void**) &input, &in_length))</DIV>
<DIV>+          return false;</DIV>
<DIV>+</DIV>
<DIV>+        if (in_length != 
block_size)</DIV>
<DIV>+        {</DIV>
<DIV>+          
rtems_rtl_set_error(EIO,"compressed read failed: bs=%u in=%u", </DIV>
<DIV>+                              
block_size, in_length);</DIV>
<DIV>+          return false;</DIV>
<DIV>+        }</DIV>
<DIV>       }</DIV>
<DIV> </DIV>
<DIV>       switch (comp->compression)</DIV>
<DIV>@@ -152,6 +197,7 @@</DIV>
<DIV>         case 
RTEMS_RTL_COMP_NONE:</DIV>
<DIV>           memcpy 
(comp->buffer, input, in_length);</DIV>
<DIV>           decompressed = 
in_length;</DIV>
<DIV>+          comp->offset += 
block_size;</DIV>
<DIV>           break;</DIV>
<DIV> </DIV>
<DIV>         case 
RTEMS_RTL_COMP_LZ77:</DIV>
<DIV>@@ -162,15 +208,79 @@</DIV>
<DIV>             
rtems_rtl_set_error (EBADF, "decompression failed");</DIV>
<DIV>             
return false;</DIV>
<DIV>           }</DIV>
<DIV>+          comp->offset += 
block_size;</DIV>
<DIV>           break;</DIV>
<DIV>+        case RTEMS_RTL_COMP_ZLIB:</DIV>
<DIV>+          if (start) </DIV>
<DIV>+          {</DIV>
<DIV>+            start = 
false;</DIV>
<DIV>+            
strm.zalloc = Z_NULL;</DIV>
<DIV>+            
strm.zfree = Z_NULL;</DIV>
<DIV>+            
strm.opaque = Z_NULL;</DIV>
<DIV>+            
strm.avail_in = 0;</DIV>
<DIV>+            
strm.next_in = Z_NULL;</DIV>
<DIV>+            ret_z = 
inflateInit(&strm);</DIV>
<DIV>+            if 
(ret_z != Z_OK)</DIV>
<DIV>+            {</DIV>
<DIV>+              
rtems_rtl_set_error(EBADF, "Invalid init inflate");</DIV>
<DIV>+              
return false;</DIV>
<DIV>+            }</DIV>
<DIV>+            ptr_in 
= out_z;</DIV>
<DIV>+            have_z 
= 0;</DIV>
<DIV>+          }</DIV>
<DIV>+          ptr_out = 
comp->buffer;</DIV>
<DIV>+          write_z = 0;</DIV>
<DIV>+          while (1)</DIV>
<DIV>+          {</DIV>
<DIV>+           while (have_z 
> 0)</DIV>
<DIV>+           {</DIV>
<DIV>+             
write_z = have_z > (block_size - (ptr_out - comp->buffer)) ?</DIV>
<DIV>+                       
block_size - (ptr_out - comp->buffer) : have_z;</DIV>
<DIV>+             
memcpy(ptr_out, ptr_in, write_z);</DIV>
<DIV>+             
ptr_out += write_z;</DIV>
<DIV>+             
ptr_in += write_z;</DIV>
<DIV>+             
have_z -= write_z;</DIV>
<DIV>+             
if ((ptr_out - comp->buffer) == block_size)</DIV>
<DIV>+               
break;</DIV>
<DIV>+           }</DIV>
<DIV>+           if ((ptr_out 
- comp->buffer) == block_size)</DIV>
<DIV>+             
break;</DIV>
<DIV>+           if 
(strm.avail_in == 0) </DIV>
<DIV>+           {</DIV>
<DIV>+             
strm.avail_in = comp->size;</DIV>
<DIV>+             
if (!rtems_rtl_obj_cache_read(comp->cache, comp->fd,</DIV>
<DIV>+                 
comp->offset, (void**) &in_z, &strm.avail_in))</DIV>
<DIV>+               
return false;</DIV>
<DIV>+             
comp->offset += strm.avail_in;</DIV>
<DIV>+             
if (strm.avail_in == 0)</DIV>
<DIV>+               
break;</DIV>
<DIV>+             
strm.next_in = in_z;</DIV>
<DIV>+           }</DIV>
<DIV>+           
strm.avail_out = comp->size * 3;</DIV>
<DIV>+           strm.next_out 
= out_z;</DIV>
<DIV>+           ptr_in = 
out_z;</DIV>
<DIV>+           ret_z = 
inflate(&strm, Z_NO_FLUSH);</DIV>
<DIV>+           if ((ret_z == 
Z_STREAM_ERROR) || (ret_z == Z_NEED_DICT) ||</DIV>
<DIV>+               
(ret_z == Z_DATA_ERROR) || (ret_z == Z_MEM_ERROR))</DIV>
<DIV>+           {</DIV>
<DIV>+             
rtems_rtl_set_error(EBADF, "Invalid inflate");</DIV>
<DIV>+             
return false;</DIV>
<DIV>+           }</DIV>
<DIV>+           have_z = 
comp->size * 3 - strm.avail_out;</DIV>
<DIV>+          }</DIV>
<DIV>+           decompressed 
= ptr_out - comp->buffer;</DIV>
<DIV>+           if 
(decompressed == 0)</DIV>
<DIV>+           {</DIV>
<DIV>+             
rtems_rtl_set_error(EBADF, "decompression failed");</DIV>
<DIV>+             
return false;</DIV>
<DIV>+           }</DIV>
<DIV>+           break;</DIV>
<DIV> </DIV>
<DIV>         default:</DIV>
<DIV>           
rtems_rtl_set_error (EINVAL, "bad compression type");</DIV>
<DIV>           return 
false;</DIV>
<DIV>       }</DIV>
<DIV> </DIV>
<DIV>-      comp->offset += block_size;</DIV>
<DIV>-</DIV>
<DIV>       comp->level = decompressed;</DIV>
<DIV>     }</DIV>
<DIV>   }</DIV>
<DIV> </DIV>
<DIV>diff -Naur cpukit/libdl/rtl-rap.c cpukit_patched/libdl/rtl-rap.c</DIV>
<DIV>--- libdl/rtl-rap.c    2019-02-18 16:36:20 +0400</DIV>
<DIV>+++ libdl_patched/rtl-rap.c    2019-02-21 11:23:33 
+0400</DIV>
<DIV>@@ -626,6 +626,10 @@</DIV>
<DIV>     if (rtems_rtl_symbol_global_find (rap->strtab + 
name) &&</DIV>
<DIV>         (ELF_ST_BIND (data & 
0xffff) != STB_WEAK))</DIV>
<DIV>     {</DIV>
<DIV>+      printf("Warning:duplicate global symbol: 
%s, use kernel symbol\n", rap->strtab + name);</DIV>
<DIV>+      obj->global_syms--; // for use 
--gc-sections (ld) and -ffunction-sections -fdata-sections (gcc)</DIV>
<DIV>+      continue;</DIV>
<DIV>+/*</DIV>
<DIV>       rtems_rtl_set_error (EINVAL,</DIV>
<DIV>                            
"duplicate global symbol: %s", rap->strtab + name);</DIV>
<DIV>       rtems_rtl_alloc_del 
(RTEMS_RTL_ALLOC_SYMBOL, obj->global_table);</DIV>
<DIV>@@ -633,6 +637,7 @@</DIV>
<DIV>       obj->global_syms = 0;</DIV>
<DIV>       obj->global_size = 0;</DIV>
<DIV>       return false;</DIV>
<DIV>+*/</DIV>
<DIV>     }</DIV>
<DIV> </DIV>
<DIV>     symsect = rtems_rtl_obj_find_section_by_index 
(obj, data >> 16);</DIV>
<DIV>@@ -731,7 +736,15 @@</DIV>
<DIV>     *compression = RTEMS_RTL_COMP_LZ77;</DIV>
<DIV>     eptr = sptr + 4;</DIV>
<DIV>   }</DIV>
<DIV>-  else</DIV>
<DIV>+  else if ((sptr[0] == 'Z') &&</DIV>
<DIV>+           (sptr[1] == 
'L') && </DIV>
<DIV>+           (sptr[2] == 
'I') &&</DIV>
<DIV>+           (sptr[3] == 
'B')) </DIV>
<DIV>+  {</DIV>
<DIV>+    *compression = RTEMS_RTL_COMP_ZLIB;</DIV>
<DIV>+    eptr = sptr + 4;</DIV>
<DIV>+  }</DIV>
<DIV>+  else </DIV>
<DIV>     return false;</DIV>
<DIV> </DIV>
<DIV>   if (*eptr != ',')</DIV>
<DIV> </DIV>
<DIV> </DIV></DIV></DIV></BODY></HTML>