Bug 693376 - Ghostscript uses globals where it should not.
Summary: Ghostscript uses globals where it should not.
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: General (show other bugs)
Version: master
Hardware: All All
: P4 normal
Assignee: Robin Watts
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-10-10 19:22 UTC by Robin Watts
Modified: 2022-01-21 15:25 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Watts 2012-10-10 19:22:02 UTC
An analysis of the globals used by a standard build of gs on linux shows the following problems:

gdevbjca.o       NOT OK
0000000000001c48 B FloydSteinbergC
00000000000000e0 D FloydSteinbergDirectionForward
0000000000001c20 B FloydSteinbergErrorsC
0000000000001c40 B FloydSteinbergErrorsG
0000000000001c38 B FloydSteinbergErrorsK
0000000000001c28 B FloydSteinbergErrorsM
0000000000001c30 B FloydSteinbergErrorsY
0000000000001c58 B FloydSteinbergG
0000000000001c54 B FloydSteinbergK
0000000000001c4c B FloydSteinbergM
0000000000001c50 B FloydSteinbergY
0000000000000000 B bjc_gamma_tableC
0000000000000400 B bjc_gamma_tableM
0000000000000800 B bjc_gamma_tableY
0000000000000c00 B bjc_j
00000000000000dc D bjc_k
0000000000000000 D bjc_rand_seed
0000000000000c20 B bjc_treshold
gdevcp50.o       BAD
0000000000000000 B copies
0000000000000000 d cp50_procs
gdevdj9.o       BAD
0000000000000000 b PageCtr
gdevfmlbp.o      BAD (paper)
0000000000001e00 d can_inits
0000000000000000 D gs_fmlbp_device
0000000000000000 b paper.10099
gdevlx32.o       BAD (gendata, hoffset, valign, penofs)
0000000000002070 d bits
0000000000002080 d colmask
0000000000000040 b gendata
0000000000000240 D gs_lxm3200_device
0000000000000020 b hoffset
0000000000002078 d ibits
00000000000020a0 d init_sequence
0000000000000000 d lxm3200_procs
0000000000000000 b penofs
000000000000000c b valign
00000000000020c0 d z12_init_sequence
gdevopvp.o       BAD
0000000000000030 b ErrorNo
00000000000000a0 b FastImageMode
00000000000012b8 d GetLastError
0000000000000020 b OpenPrinter
0000000000000028 b OpenPrinter_0_2
0000000000000040 b apiEntry
0000000000000048 b apiEntry_0_2
00000000000000b4 b base_color_index
0000000000000090 b beginPage
00000000000000a4 b begin_image
00000000000005e0 b brush.21884
0000000000000620 b buff.17373
0000000000000618 b buff.17579
0000000000000610 b buff.17591
0000000000000608 b buff.17646
00000000000000ac b change_cspace
00000000000000a8 b change_paint_mode
0000000000001320 d colorDepth_0_2
00000000000012ac d colorSpace
00000000000000b0 b color_index
00000000000012c0 d cspace_0_2_to_1_0
00000000000012e0 d cspace_1_0_to_0_2
0000000000000000 d cspace_available
0000000000000058 b docInfo
0000000000000098 b fastImage
0000000000000018 b handle
0000000000001300 d iformat_1_0_to_0_2
00000000000003c0 b imageDecode
0000000000000000 b inkjet
0000000000000050 b jobInfo
0000000000000070 b margins
0000000000000038 b nApiEntry
0000000000000fc0 d opvp_vector_procs
00000000000012a4 d outputFD
0000000000000648 b page_info.17250
00000000000000c0 b palette
0000000000000020 D paperTable
00000000000012a8 d printerContext
0000000000000010 b printerModel
0000000000001060 d prn_oprp_procs
00000000000005c8 b reverse_image
0000000000000060 b savedColorSpace
0000000000000080 b shift
0000000000000660 b tEntry.16867
00000000000012a0 d vector
0000000000000008 b vectorDriver
0000000000000068 b vectorFillColor
00000000000012b0 d zoom
0000000000000088 b zoomAuto
000000000000008c b zooming
gdevpdtt.o       BAD
0000000000000000 d standard_glyph_code_for_notdef
gdevstc4.o       BAD (dir)
0000000000000010 d colour.10505
0000000000000000 d dir.10623
gdevupd.o        BAD (sigupd)
0000000000000240 D gs_uniprint_device
0000000000000000 b sigupd
0000000000000000 d upd_procs
gdevxini.o       BAD(x_error_handler)
0000000000000000 b x_error_handler
gsicc_lcms2_0.o  BAD (name)
0000000000000000 d gs_cms_memhandler
0000000000000000 b name.6563
gsicc_lcms2.o    BAD (name)
0000000000000000 d gs_cms_memhandler
0000000000000000 b name.6563
mediasize.o      BAD(entries, sorted_list)
0000000000000000 b checked
0000000000000004 b entries.2217
0000000000000020 b sorted_list.2216
pclsize.o        BAD
0000000000000000 d code_map
0000000000000108 b initialized.2140
0000000000000000 b initialized.2166
0000000000000020 b inverse_map.2165
tif_luv.o        BAD
0000000000000000 b initialized.5541
0000000000000020 b oog_table.5540
0000000000000000 d uv_row
vdtrace.o        BAD
0000000000000010 b px
0000000000000018 b py
0000000000000000 D vd_flags
0000000000000000 B vd_trace0
0000000000000008 B vd_trace1
Comment 1 Robin Watts 2012-10-10 19:24:49 UTC
gdevpdtt.o is actually OK.
Comment 2 Robin Watts 2012-10-11 19:37:00 UTC
gsicc_lcms2 and gsicc_lcms are now fixed.
Comment 3 Peter Cherepanov 2021-02-08 20:29:26 UTC
I found the following global variables in all programs of 'ghostpdl'.

clist_io_procs_memory_global
clist_io_procs_file_global
_cmsIntentsPluginChunk
_cmsCurvesPluginChunk
_cmsInterpPluginChunk
_cmsOptimizationPluginChunk
_cmsFormattersPluginChunk
_cmsTagPluginChunk
_cmsTagTypePluginChunk
_cmsMPETypePluginChunk
_cmsTransformPluginChunk
_TIFFerrorHandlerExt
_TIFFwarningHandlerExt
_TIFFerrorHandler
_TIFFwarningHandler
hdr_id
gs_debug
gs_scan_comment_proc
gs_scan_dsc_proc
pjl_permanent_soft_fonts
xps_doc_trace
xps_zip_trace

The symbol maps were generated with:
XLDFLAGS=-Wl,-M make -e 2>&1 | tee build.log

The log was parsed by the following Python script:
acc = {}
try: 
  while True:
    s = input()
    ss = s.split()
    if s[1:5] == ".bss":
      bss = True
    elif s[1:5] != "    ":
      bss = False
    else:
      if (bss):
        acc[ss[1]] = True
except EOFError:
  pass
for a in acc:
  print(a)
Comment 4 Robin Watts 2022-01-21 13:30:21 UTC
The following commits remove all the globals except for the lcms ones and the tiff ones.

commit e68c710d2df3f6e74c66a2c78f668502039a0ef3 (golden/master)
Author: Robin Watts <Robin.Watts@artifex.com>
Date:   Fri Jan 21 13:14:33 2022 +0000

    Bug 693376: Move pjl_permanent_soft_fonts to pjl state structure.

    Move a global to the pjl state. The global is initialised when
    the pjl state is allocated, so the lifespans match.

commit 4abddf623a6f2cb6291b06235fb63b58262ea8ab
Author: Robin Watts <Robin.Watts@artifex.com>
Date:   Fri Jan 21 12:17:25 2022 +0000

    Bug 693376: Strip out hdr_id.

    This is part of some debugging code that hoped to give every
    memory allocation within gs (at least in single threaded mode)
    a unique id number.

    In consultation with Chris, we decided it's never really been
    used, so we're stripping it out.

commit a017fee74598e9f9a67353086eeaf4fd7edf9e7b
Author: Robin Watts <Robin.Watts@artifex.com>
Date:   Fri Jan 21 11:41:20 2022 +0000

    Bug 693376: Eliminate postscript scanner handling globals.

    There are 2 global vars (gs_scan_comment_proc and gs_scan_dsc_proc)
    that can (I think) be used to intercept comment scanning in the PS
    interpreter. These are undocumented anywhere, and we never actually
    set these variables in our code.

    Just over 10 years ago, we renamed these with no complaints from
    anyone, which makes us believe that they are unused. We excise them
    completely here.

commit 3ed3f5b01ebbe9106ff8c08d6acb29a789e63288
Author: Robin Watts <Robin.Watts@artifex.com>
Date:   Fri Jan 21 11:07:03 2022 +0000

    Bug 693376: Remove 2 vestigial debugging variables.

    It seems xps_doc_trace and xps_zip_trace are never actually used
    other than to be set.

commit 6f53ab7da8baf5322236fb2a84e34204cfcc48e2
Author: Robin Watts <Robin.Watts@artifex.com>
Date:   Fri Jan 21 10:49:43 2022 +0000

    Bug 693376: Remove 2 more global variables from Ghostscript.

    These should not have been a problem, as they are 'monotonic' in
    any given build, but nonetheless, this is neater.

    Remove clist_io_procs_memory_global and clist_io_procs_file_global.
    These hold pointers to the io_procs structures for either memory
    or file writing as appropriate. Here we move them into
    gs_lib_ctx_core_t.
Comment 5 Robin Watts 2022-01-21 15:25:03 UTC
I couldn't make the python script work, so I did:

  make LDFLAGS="-Xlinker -Map=output.map"

and then manually looked at the produced output.map.

I see the following symbols left:

  _cmsIntentsPluginChunk
  _cmsCurvesPluginChunk
  _cmsInterpPluginChunk
  _cmsOptimizationPluginChunk
  _cmsFormattersPluginChunk
  _cmsTagPluginChunk
  _cmsTagTypePluginChunk
  _cmsMPETypePluginChunk
  _cmsTransformPluginChunk
  _TIFFerrorHandlerExt
  _TIFFwarningHandlerExt
  _TIFFerrorHandler
  _TIFFwarningHandler
  gs_debug

The _cms ones are unavoidable (without radical rewriting of lcms). I believe they are safe because they get set once at startup, and then don't change.

The _TIFF ones are unavoidable (without forking libtiff). I hope they don't affect us.

gs_debug is (as the name suggests) only used for debugging, so that's fine.

I'm going to close this bug.