~ubuntu-branches/ubuntu/wily/clamav/wily-proposed

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/MC/WinCOFFStreamer.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Sebastian Andrzej Siewior, Andreas Cadhalpun, Scott Kitterman, Javier Fernández-Sanguino
  • Date: 2015-01-28 00:25:13 UTC
  • mfrom: (0.48.14 sid)
  • Revision ID: package-import@ubuntu.com-20150128002513-lil2oi74cooy4lzr
Tags: 0.98.6+dfsg-1
[ Sebastian Andrzej Siewior ]
* update "fix-ssize_t-size_t-off_t-printf-modifier", include of misc.h was
  missing but was pulled in via the systemd patch.
* Don't leak return codes from libmspack to clamav API. (Closes: #774686).

[ Andreas Cadhalpun ]
* Add patch to avoid emitting incremental progress messages when not
  outputting to a terminal. (Closes: #767350)
* Update lintian-overrides for unused-file-paragraph-in-dep5-copyright.
* clamav-base.postinst: always chown /var/log/clamav and /var/lib/clamav
  to clamav:clamav, not only on fresh installations. (Closes: #775400)
* Adapt the clamav-daemon and clamav-freshclam logrotate scripts,
  so that they correctly work under systemd.
* Move the PidFile variable from the clamd/freshclam configuration files
  to the init scripts. This makes the init scripts more robust against
  misconfiguration and avoids error messages with systemd. (Closes: #767353)
* debian/copyright: drop files from Files-Excluded only present in github
  tarballs
* Drop Workaround-a-bug-in-libc-on-Hurd.patch, because hurd got fixed.
  (see #752237)
* debian/rules: Remove useless --with-system-tommath --without-included-ltdl
  configure options.

[ Scott Kitterman ]
* Stop stripping llvm when repacking the tarball as the system llvm on some
  releases is too old to use
* New upstream bugfix release
  - Library shared object revisions.
  - Includes a patch from Sebastian Andrzej Siewior making ClamAV pid files
    compatible with systemd.
  - Fix a heap out of bounds condition with crafted Yoda's crypter files.
    This issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted mew packer files. This
    issue was discovered by Felix Groebert of the Google Security Team.
  - Fix a heap out of bounds condition with crafted upx packer files. This
    issue was discovered by Kevin Szkudlapski of Quarkslab.
  - Fix a heap out of bounds condition with crafted upack packer files. This
    issue was discovered by Sebastian Andrzej Siewior. CVE-2014-9328.
  - Compensate a crash due to incorrect compiler optimization when handling
    crafted petite packer files. This issue was discovered by Sebastian
    Andrzej Siewior.
* Update lintian override for embedded zlib to match new so version

[ Javier Fernández-Sanguino ]
* Updated Spanish Debconf template translation (Closes: #773563)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===-- llvm/MC/WinCOFFStreamer.cpp -----------------------------*- C++ -*-===//
 
2
//
 
3
//                     The LLVM Compiler Infrastructure
 
4
//
 
5
// This file is distributed under the University of Illinois Open Source
 
6
// License. See LICENSE.TXT for details.
 
7
//
 
8
//===----------------------------------------------------------------------===//
 
9
//
 
10
// This file contains an implementation of a Win32 COFF object file streamer.
 
11
//
 
12
//===----------------------------------------------------------------------===//
 
13
 
 
14
#define DEBUG_TYPE "WinCOFFStreamer"
 
15
 
 
16
#include "llvm/MC/MCObjectStreamer.h"
 
17
#include "llvm/MC/MCContext.h"
 
18
#include "llvm/MC/MCSection.h"
 
19
#include "llvm/MC/MCSymbol.h"
 
20
#include "llvm/MC/MCExpr.h"
 
21
#include "llvm/MC/MCValue.h"
 
22
#include "llvm/MC/MCAssembler.h"
 
23
#include "llvm/MC/MCAsmLayout.h"
 
24
#include "llvm/MC/MCCodeEmitter.h"
 
25
#include "llvm/MC/MCSectionCOFF.h"
 
26
#include "llvm/Target/TargetRegistry.h"
 
27
#include "llvm/Target/TargetAsmBackend.h"
 
28
#include "llvm/ADT/StringMap.h"
 
29
 
 
30
#include "llvm/Support/COFF.h"
 
31
#include "llvm/Support/Debug.h"
 
32
#include "llvm/Support/ErrorHandling.h"
 
33
#include "llvm/Support/raw_ostream.h"
 
34
using namespace llvm;
 
35
 
 
36
namespace {
 
37
class WinCOFFStreamer : public MCObjectStreamer {
 
38
public:
 
39
  MCSymbol const *CurSymbol;
 
40
 
 
41
  WinCOFFStreamer(MCContext &Context,
 
42
                  TargetAsmBackend &TAB,
 
43
                  MCCodeEmitter &CE,
 
44
                  raw_ostream &OS);
 
45
 
 
46
  void AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
 
47
                       unsigned ByteAlignment, bool External);
 
48
 
 
49
  // MCStreamer interface
 
50
 
 
51
  virtual void EmitLabel(MCSymbol *Symbol);
 
52
  virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
 
53
  virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
 
54
  virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
 
55
  virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
 
56
  virtual void BeginCOFFSymbolDef(MCSymbol const *Symbol);
 
57
  virtual void EmitCOFFSymbolStorageClass(int StorageClass);
 
58
  virtual void EmitCOFFSymbolType(int Type);
 
59
  virtual void EndCOFFSymbolDef();
 
60
  virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
 
61
  virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
 
62
                                unsigned ByteAlignment);
 
63
  virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size);
 
64
  virtual void EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
 
65
                            unsigned Size,unsigned ByteAlignment);
 
66
  virtual void EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
 
67
                              uint64_t Size, unsigned ByteAlignment);
 
68
  virtual void EmitBytes(StringRef Data, unsigned AddrSpace);
 
69
  virtual void EmitValue(const MCExpr *Value, unsigned Size,
 
70
                         unsigned AddrSpace);
 
71
  virtual void EmitGPRel32Value(const MCExpr *Value);
 
72
  virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
 
73
                                   unsigned ValueSize, unsigned MaxBytesToEmit);
 
74
  virtual void EmitCodeAlignment(unsigned ByteAlignment,
 
75
                                 unsigned MaxBytesToEmit);
 
76
  virtual void EmitValueToOffset(const MCExpr *Offset, unsigned char Value);
 
77
  virtual void EmitFileDirective(StringRef Filename);
 
78
  virtual void EmitDwarfFileDirective(unsigned FileNo,StringRef Filename);
 
79
  virtual void EmitInstruction(const MCInst &Instruction);
 
80
  virtual void Finish();
 
81
};
 
82
} // end anonymous namespace.
 
83
 
 
84
WinCOFFStreamer::WinCOFFStreamer(MCContext &Context,
 
85
                                 TargetAsmBackend &TAB,
 
86
                                 MCCodeEmitter &CE,
 
87
                                 raw_ostream &OS)
 
88
    : MCObjectStreamer(Context, TAB, OS, &CE)
 
89
    , CurSymbol(NULL) {
 
90
}
 
91
 
 
92
void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
 
93
                                      unsigned ByteAlignment, bool External) {
 
94
  assert(!Symbol->isInSection() && "Symbol must not already have a section!");
 
95
 
 
96
  std::string SectionName(".bss$linkonce");
 
97
  SectionName.append(Symbol->getName().begin(), Symbol->getName().end());
 
98
 
 
99
  MCSymbolData &SymbolData = getAssembler().getOrCreateSymbolData(*Symbol);
 
100
 
 
101
  unsigned Characteristics =
 
102
    COFF::IMAGE_SCN_LNK_COMDAT |
 
103
    COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |
 
104
    COFF::IMAGE_SCN_MEM_READ |
 
105
    COFF::IMAGE_SCN_MEM_WRITE;
 
106
 
 
107
  int Selection = COFF::IMAGE_COMDAT_SELECT_LARGEST;
 
108
 
 
109
  const MCSection *Section = MCStreamer::getContext().getCOFFSection(
 
110
    SectionName, Characteristics, Selection, SectionKind::getBSS());
 
111
 
 
112
  MCSectionData &SectionData = getAssembler().getOrCreateSectionData(*Section);
 
113
 
 
114
  if (SectionData.getAlignment() < ByteAlignment)
 
115
    SectionData.setAlignment(ByteAlignment);
 
116
 
 
117
  SymbolData.setExternal(External);
 
118
 
 
119
  Symbol->setSection(*Section);
 
120
 
 
121
  if (ByteAlignment != 1)
 
122
      new MCAlignFragment(ByteAlignment, 0, 0, ByteAlignment, &SectionData);
 
123
 
 
124
  SymbolData.setFragment(new MCFillFragment(0, 0, Size, &SectionData));
 
125
}
 
126
 
 
127
// MCStreamer interface
 
128
 
 
129
void WinCOFFStreamer::EmitLabel(MCSymbol *Symbol) {
 
130
  // TODO: This is copied almost exactly from the MachOStreamer. Consider
 
131
  // merging into MCObjectStreamer?
 
132
  assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
 
133
  assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
 
134
  assert(CurSection && "Cannot emit before setting section!");
 
135
 
 
136
  Symbol->setSection(*CurSection);
 
137
 
 
138
  MCSymbolData &SD = getAssembler().getOrCreateSymbolData(*Symbol);
 
139
 
 
140
  // FIXME: This is wasteful, we don't necessarily need to create a data
 
141
  // fragment. Instead, we should mark the symbol as pointing into the data
 
142
  // fragment if it exists, otherwise we should just queue the label and set its
 
143
  // fragment pointer when we emit the next fragment.
 
144
  MCDataFragment *DF = getOrCreateDataFragment();
 
145
 
 
146
  assert(!SD.getFragment() && "Unexpected fragment on symbol data!");
 
147
  SD.setFragment(DF);
 
148
  SD.setOffset(DF->getContents().size());
 
149
}
 
150
 
 
151
void WinCOFFStreamer::EmitAssemblerFlag(MCAssemblerFlag Flag) {
 
152
  llvm_unreachable("not implemented");
 
153
}
 
154
 
 
155
void WinCOFFStreamer::EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) {
 
156
  // TODO: This is exactly the same as MachOStreamer. Consider merging into
 
157
  // MCObjectStreamer.
 
158
  getAssembler().getOrCreateSymbolData(*Symbol);
 
159
  AddValueSymbols(Value);
 
160
  Symbol->setVariableValue(Value);
 
161
}
 
162
 
 
163
void WinCOFFStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
 
164
                                          MCSymbolAttr Attribute) {
 
165
  switch (Attribute) {
 
166
  case MCSA_WeakReference:
 
167
    getAssembler().getOrCreateSymbolData(*Symbol).modifyFlags(
 
168
      COFF::SF_WeakReference,
 
169
      COFF::SF_WeakReference);
 
170
    break;
 
171
 
 
172
  case MCSA_Global:
 
173
    getAssembler().getOrCreateSymbolData(*Symbol).setExternal(true);
 
174
    break;
 
175
 
 
176
  default:
 
177
    llvm_unreachable("unsupported attribute");
 
178
    break;
 
179
  }
 
180
}
 
181
 
 
182
void WinCOFFStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
 
183
  llvm_unreachable("not implemented");
 
184
}
 
185
 
 
186
void WinCOFFStreamer::BeginCOFFSymbolDef(MCSymbol const *Symbol) {
 
187
  assert(CurSymbol == NULL && "EndCOFFSymbolDef must be called between calls "
 
188
                              "to BeginCOFFSymbolDef!");
 
189
  CurSymbol = Symbol;
 
190
}
 
191
 
 
192
void WinCOFFStreamer::EmitCOFFSymbolStorageClass(int StorageClass) {
 
193
  assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
 
194
  assert((StorageClass & ~0xFF) == 0 && "StorageClass must only have data in "
 
195
                                        "the first byte!");
 
196
 
 
197
  getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags(
 
198
    StorageClass << COFF::SF_ClassShift,
 
199
    COFF::SF_ClassMask);
 
200
}
 
201
 
 
202
void WinCOFFStreamer::EmitCOFFSymbolType(int Type) {
 
203
  assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
 
204
  assert((Type & ~0xFFFF) == 0 && "Type must only have data in the first 2 "
 
205
                                  "bytes");
 
206
 
 
207
  getAssembler().getOrCreateSymbolData(*CurSymbol).modifyFlags(
 
208
    Type << COFF::SF_TypeShift,
 
209
    COFF::SF_TypeMask);
 
210
}
 
211
 
 
212
void WinCOFFStreamer::EndCOFFSymbolDef() {
 
213
  assert(CurSymbol != NULL && "BeginCOFFSymbolDef must be called first!");
 
214
  CurSymbol = NULL;
 
215
}
 
216
 
 
217
void WinCOFFStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
 
218
  llvm_unreachable("not implemented");
 
219
}
 
220
 
 
221
void WinCOFFStreamer::EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
 
222
                                       unsigned ByteAlignment) {
 
223
  AddCommonSymbol(Symbol, Size, ByteAlignment, true);
 
224
}
 
225
 
 
226
void WinCOFFStreamer::EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size) {
 
227
  AddCommonSymbol(Symbol, Size, 1, false);
 
228
}
 
229
 
 
230
void WinCOFFStreamer::EmitZerofill(const MCSection *Section, MCSymbol *Symbol,
 
231
                                   unsigned Size,unsigned ByteAlignment) {
 
232
  llvm_unreachable("not implemented");
 
233
}
 
234
 
 
235
void WinCOFFStreamer::EmitTBSSSymbol(const MCSection *Section, MCSymbol *Symbol,
 
236
                                     uint64_t Size, unsigned ByteAlignment) {
 
237
  llvm_unreachable("not implemented");
 
238
}
 
239
 
 
240
void WinCOFFStreamer::EmitBytes(StringRef Data, unsigned AddrSpace) {
 
241
  // TODO: This is copied exactly from the MachOStreamer. Consider merging into
 
242
  // MCObjectStreamer?
 
243
  getOrCreateDataFragment()->getContents().append(Data.begin(), Data.end());
 
244
}
 
245
 
 
246
void WinCOFFStreamer::EmitValue(const MCExpr *Value, unsigned Size,
 
247
                                unsigned AddrSpace) {
 
248
  assert(AddrSpace == 0 && "Address space must be 0!");
 
249
 
 
250
  // TODO: This is copied exactly from the MachOStreamer. Consider merging into
 
251
  // MCObjectStreamer?
 
252
  MCDataFragment *DF = getOrCreateDataFragment();
 
253
 
 
254
  // Avoid fixups when possible.
 
255
  int64_t AbsValue;
 
256
  if (AddValueSymbols(Value)->EvaluateAsAbsolute(AbsValue)) {
 
257
    // FIXME: Endianness assumption.
 
258
    for (unsigned i = 0; i != Size; ++i)
 
259
      DF->getContents().push_back(uint8_t(AbsValue >> (i * 8)));
 
260
  } else {
 
261
    DF->addFixup(MCFixup::Create(DF->getContents().size(),
 
262
                                 AddValueSymbols(Value),
 
263
                                 MCFixup::getKindForSize(Size)));
 
264
    DF->getContents().resize(DF->getContents().size() + Size, 0);
 
265
  }
 
266
}
 
267
 
 
268
void WinCOFFStreamer::EmitGPRel32Value(const MCExpr *Value) {
 
269
  llvm_unreachable("not implemented");
 
270
}
 
271
 
 
272
void WinCOFFStreamer::EmitValueToAlignment(unsigned ByteAlignment,
 
273
                                           int64_t Value,
 
274
                                           unsigned ValueSize,
 
275
                                           unsigned MaxBytesToEmit) {
 
276
  // TODO: This is copied exactly from the MachOStreamer. Consider merging into
 
277
  // MCObjectStreamer?
 
278
  if (MaxBytesToEmit == 0)
 
279
    MaxBytesToEmit = ByteAlignment;
 
280
  new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit,
 
281
                      getCurrentSectionData());
 
282
 
 
283
  // Update the maximum alignment on the current section if necessary.
 
284
  if (ByteAlignment > getCurrentSectionData()->getAlignment())
 
285
    getCurrentSectionData()->setAlignment(ByteAlignment);
 
286
}
 
287
 
 
288
void WinCOFFStreamer::EmitCodeAlignment(unsigned ByteAlignment,
 
289
                                        unsigned MaxBytesToEmit) {
 
290
  // TODO: This is copied exactly from the MachOStreamer. Consider merging into
 
291
  // MCObjectStreamer?
 
292
  if (MaxBytesToEmit == 0)
 
293
    MaxBytesToEmit = ByteAlignment;
 
294
  MCAlignFragment *F = new MCAlignFragment(ByteAlignment, 0, 1, MaxBytesToEmit,
 
295
                                           getCurrentSectionData());
 
296
  F->setEmitNops(true);
 
297
 
 
298
  // Update the maximum alignment on the current section if necessary.
 
299
  if (ByteAlignment > getCurrentSectionData()->getAlignment())
 
300
    getCurrentSectionData()->setAlignment(ByteAlignment);
 
301
}
 
302
 
 
303
void WinCOFFStreamer::EmitValueToOffset(const MCExpr *Offset,
 
304
                                        unsigned char Value) {
 
305
  llvm_unreachable("not implemented");
 
306
}
 
307
 
 
308
void WinCOFFStreamer::EmitFileDirective(StringRef Filename) {
 
309
  // Ignore for now, linkers don't care, and proper debug
 
310
  // info will be a much large effort.
 
311
}
 
312
 
 
313
void WinCOFFStreamer::EmitDwarfFileDirective(unsigned FileNo,
 
314
                                             StringRef Filename) {
 
315
  llvm_unreachable("not implemented");
 
316
}
 
317
 
 
318
void WinCOFFStreamer::EmitInstruction(const MCInst &Instruction) {
 
319
  for (unsigned i = 0, e = Instruction.getNumOperands(); i != e; ++i)
 
320
    if (Instruction.getOperand(i).isExpr())
 
321
      AddValueSymbols(Instruction.getOperand(i).getExpr());
 
322
 
 
323
  getCurrentSectionData()->setHasInstructions(true);
 
324
 
 
325
  MCInstFragment *Fragment =
 
326
    new MCInstFragment(Instruction, getCurrentSectionData());
 
327
 
 
328
  raw_svector_ostream VecOS(Fragment->getCode());
 
329
 
 
330
  getAssembler().getEmitter().EncodeInstruction(Instruction, VecOS,
 
331
                                                Fragment->getFixups());
 
332
}
 
333
 
 
334
void WinCOFFStreamer::Finish() {
 
335
  MCObjectStreamer::Finish();
 
336
}
 
337
 
 
338
namespace llvm
 
339
{
 
340
  MCStreamer *createWinCOFFStreamer(MCContext &Context,
 
341
                                    TargetAsmBackend &TAB,
 
342
                                    MCCodeEmitter &CE,
 
343
                                    raw_ostream &OS,
 
344
                                    bool RelaxAll) {
 
345
    WinCOFFStreamer *S = new WinCOFFStreamer(Context, TAB, CE, OS);
 
346
    S->getAssembler().setRelaxAll(RelaxAll);
 
347
    return S;
 
348
  }
 
349
}